1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-05 03:03:26 +00:00
Files
browser/apps/cli/webpack.shared.js
addisonbeck 2266a17a13 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
2025-09-09 06:51:55 -04:00

111 lines
2.4 KiB
JavaScript

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,
};