mirror of
https://github.com/bitwarden/browser
synced 2026-02-11 14:04:03 +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:
110
apps/cli/webpack.shared.js
Normal file
110
apps/cli/webpack.shared.js
Normal file
@@ -0,0 +1,110 @@
|
||||
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");
|
||||
|
||||
const getSharedConfig = (options) => {
|
||||
const {
|
||||
env,
|
||||
mode,
|
||||
entryPoint,
|
||||
outputPath,
|
||||
modulesPath,
|
||||
tsconfigPath,
|
||||
localesPath,
|
||||
externalsModulesDir,
|
||||
} = options;
|
||||
|
||||
const envConfig = config.load(env);
|
||||
config.log(envConfig);
|
||||
|
||||
return {
|
||||
mode: mode,
|
||||
target: "node",
|
||||
devtool: env === "development" ? "eval-source-map" : "source-map",
|
||||
node: {
|
||||
__dirname: false,
|
||||
__filename: false,
|
||||
},
|
||||
entry: {
|
||||
bw: entryPoint,
|
||||
},
|
||||
optimization: {
|
||||
minimize: false,
|
||||
},
|
||||
resolve: {
|
||||
extensions: [".ts", ".js"],
|
||||
symlinks: false,
|
||||
modules: modulesPath,
|
||||
plugins: [new TsconfigPathsPlugin({ configFile: tsconfigPath })],
|
||||
},
|
||||
output: {
|
||||
filename: "[name].js",
|
||||
path: outputPath,
|
||||
clean: true,
|
||||
},
|
||||
module: { rules: getModuleRules() },
|
||||
plugins: getPlugins(env, envConfig, localesPath),
|
||||
externals: getExternals(externalsModulesDir),
|
||||
experiments: {
|
||||
asyncWebAssembly: true,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
const getModuleRules = () => {
|
||||
return [
|
||||
{
|
||||
test: /\.ts$/,
|
||||
use: "ts-loader",
|
||||
exclude: path.resolve(__dirname, "node_modules"),
|
||||
},
|
||||
];
|
||||
};
|
||||
|
||||
const getPlugins = (env, envConfig, localesPath) => {
|
||||
return [
|
||||
new CopyWebpackPlugin({
|
||||
patterns: [{ from: localesPath, 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 getExternals = (externalsModulesDir) => {
|
||||
return [
|
||||
nodeExternals({
|
||||
modulesDir: externalsModulesDir,
|
||||
allowlist: [/@bitwarden/],
|
||||
}),
|
||||
];
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getSharedConfig,
|
||||
getModuleRules,
|
||||
getPlugins,
|
||||
getExternals,
|
||||
};
|
||||
Reference in New Issue
Block a user