1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-27 17:18:04 +01:00
bitwarden-browser/apps/cli/webpack.config.js

90 lines
2.0 KiB
JavaScript
Raw Normal View History

2021-12-20 18:04:00 +01:00
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");
2018-05-15 05:16:59 +02:00
if (process.env.NODE_ENV == null) {
2021-12-20 18:04:00 +01:00
process.env.NODE_ENV = "development";
2018-05-15 05:16:59 +02:00
}
2021-12-20 18:04:00 +01:00
const ENV = (process.env.ENV = process.env.NODE_ENV);
2018-05-15 05:16:59 +02:00
const envConfig = config.load(ENV);
config.log(envConfig);
2018-05-15 05:16:59 +02:00
const moduleRules = [
2021-12-20 18:04:00 +01:00
{
test: /\.ts$/,
use: "ts-loader",
2021-12-20 18:04:00 +01:00
exclude: path.resolve(__dirname, "node_modules"),
},
2018-05-15 05:16:59 +02:00
];
const plugins = [
2021-12-20 18:04:00 +01:00
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$/,
}),
2018-05-15 05:16:59 +02:00
];
const webpackConfig = {
2021-12-20 18:04:00 +01:00
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")],
2021-12-20 18:04:00 +01:00
plugins: [new TsconfigPathsPlugin({ configFile: "./tsconfig.json" })],
},
output: {
filename: "[name].js",
path: path.resolve(__dirname, "build"),
2024-03-12 18:02:47 +01:00
clean: true,
2021-12-20 18:04:00 +01:00
},
module: { rules: moduleRules },
plugins: plugins,
externals: [
nodeExternals({
modulesDir: "../../node_modules",
2022-06-14 17:10:53 +02:00
allowlist: [/@bitwarden/],
}),
],
experiments: {
asyncWebAssembly: true,
},
2018-05-15 05:16:59 +02:00
};
module.exports = webpackConfig;