1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-28 18:43:26 +00:00

feat(cli): integrate Nx with CLI application

- Add project.json with build, serve, test, and lint targets
- Support both OSS and Bit configurations via Nx configurations
- Maintain backward compatibility with existing npm build scripts
- Update webpack configs to work with both Nx and direct webpack CLI calls
- Enable nx build cli --configuration=[oss|oss-dev|bit|bit-dev] commands
- Enable nx serve cli for development workflow with watch mode
- Preserve all existing npm run build:* commands for compatibility
This commit is contained in:
addisonbeck
2025-08-25 14:35:08 -04:00
parent 9b0bc38459
commit 2266a17a13
8 changed files with 7057 additions and 2715 deletions

View File

@@ -1,89 +1,2 @@
const path = require("path");
const webpack = require("webpack");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const nodeExternals = require("webpack-node-externals");
const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin");
const config = require("./config/config");
if (process.env.NODE_ENV == null) {
process.env.NODE_ENV = "development";
}
const ENV = (process.env.ENV = process.env.NODE_ENV);
const envConfig = config.load(ENV);
config.log(envConfig);
const moduleRules = [
{
test: /\.ts$/,
use: "ts-loader",
exclude: path.resolve(__dirname, "node_modules"),
},
];
const plugins = [
new CopyWebpackPlugin({
patterns: [{ from: "./src/locales", to: "locales" }],
}),
new webpack.DefinePlugin({
"process.env.BWCLI_ENV": JSON.stringify(ENV),
}),
new webpack.BannerPlugin({
banner: "#!/usr/bin/env node",
raw: true,
}),
new webpack.IgnorePlugin({
resourceRegExp: /^encoding$/,
contextRegExp: /node-fetch/,
}),
new webpack.EnvironmentPlugin({
ENV: ENV,
BWCLI_ENV: ENV,
FLAGS: envConfig.flags,
DEV_FLAGS: envConfig.devFlags,
}),
new webpack.IgnorePlugin({
resourceRegExp: /canvas/,
contextRegExp: /jsdom$/,
}),
];
const webpackConfig = {
mode: ENV,
target: "node",
devtool: ENV === "development" ? "eval-source-map" : "source-map",
node: {
__dirname: false,
__filename: false,
},
entry: {
bw: "./src/bw.ts",
},
optimization: {
minimize: false,
},
resolve: {
extensions: [".ts", ".js"],
symlinks: false,
modules: [path.resolve("../../node_modules")],
plugins: [new TsconfigPathsPlugin({ configFile: "./tsconfig.json" })],
},
output: {
filename: "[name].js",
path: path.resolve(__dirname, "build"),
clean: true,
},
module: { rules: moduleRules },
plugins: plugins,
externals: [
nodeExternals({
modulesDir: "../../node_modules",
allowlist: [/@bitwarden/],
}),
],
experiments: {
asyncWebAssembly: true,
},
};
module.exports = webpackConfig;
// For backward compatibility with existing npm scripts
module.exports = require("./webpack.npm.config.js");