1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-14 10:26:19 +01:00
bitwarden-browser/apps/desktop/webpack.main.js

90 lines
2.0 KiB
JavaScript
Raw Normal View History

2021-12-20 15:47:17 +01:00
const path = require("path");
const { merge } = require("webpack-merge");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin");
const configurator = require("./config/config");
const { EnvironmentPlugin } = require("webpack");
2018-01-23 19:59:01 +01:00
2021-12-20 15:47:17 +01:00
const NODE_ENV = process.env.NODE_ENV == null ? "development" : process.env.NODE_ENV;
console.log("Main process config");
const envConfig = configurator.load(NODE_ENV);
configurator.log(envConfig);
2018-01-23 19:59:01 +01:00
const common = {
2021-12-20 15:47:17 +01:00
module: {
rules: [
{
test: /\.tsx?$/,
use: "ts-loader",
exclude: /node_modules\/(?!(@bitwarden)\/).*/,
},
],
},
plugins: [],
resolve: {
extensions: [".tsx", ".ts", ".js"],
plugins: [new TsconfigPathsPlugin({ configFile: "./tsconfig.json" })],
},
};
const prod = {
2021-12-20 15:47:17 +01:00
output: {
filename: "[name].js",
path: path.resolve(__dirname, "build"),
},
};
const dev = {
2021-12-20 15:47:17 +01:00
output: {
filename: "[name].js",
path: path.resolve(__dirname, "build"),
devtoolModuleFilenameTemplate: "[absolute-resource-path]",
},
devtool: "cheap-source-map",
};
2018-01-23 19:59:01 +01:00
const main = {
2021-12-20 15:47:17 +01:00
mode: NODE_ENV,
target: "electron-main",
node: {
__dirname: false,
__filename: false,
},
entry: {
main: "./src/entry.ts",
},
optimization: {
minimize: false,
},
module: {
rules: [
{
test: /\.node$/,
loader: "node-loader",
},
2018-01-23 19:59:01 +01:00
],
2021-12-20 15:47:17 +01:00
},
plugins: [
new CopyWebpackPlugin({
patterns: [
"./src/package.json",
{ from: "./src/images", to: "images" },
{ from: "./src/locales", to: "locales" },
],
}),
new EnvironmentPlugin({
FLAGS: envConfig.flags,
DEV_FLAGS: NODE_ENV === "development" ? envConfig.devFlags : {},
}),
2021-12-20 15:47:17 +01:00
],
externals: {
"electron-reload": "commonjs2 electron-reload",
"@bitwarden/desktop-napi": "commonjs2 @bitwarden/desktop-napi",
argon2: "commonjs2 argon2",
},
2018-01-23 19:59:01 +01:00
};
2021-12-20 15:47:17 +01:00
module.exports = merge(common, NODE_ENV === "development" ? dev : prod, main);