2018-01-23 19:59:01 +01:00
|
|
|
const path = require("path");
|
2021-04-23 10:45:30 +02:00
|
|
|
const { merge } = require("webpack-merge");
|
2018-01-23 19:59:01 +01:00
|
|
|
const CopyWebpackPlugin = require("copy-webpack-plugin");
|
2021-06-07 19:26:36 +02:00
|
|
|
const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin");
|
2022-09-01 22:08:47 +02:00
|
|
|
const configurator = require("./config/config");
|
|
|
|
const { EnvironmentPlugin } = require("webpack");
|
2018-01-23 19:59:01 +01:00
|
|
|
|
2021-06-10 21:37:39 +02:00
|
|
|
const NODE_ENV = process.env.NODE_ENV == null ? "development" : process.env.NODE_ENV;
|
2021-06-10 18:50:59 +02:00
|
|
|
|
2022-09-01 22:08:47 +02:00
|
|
|
console.log("Main process config");
|
|
|
|
const envConfig = configurator.load(NODE_ENV);
|
|
|
|
configurator.log(envConfig);
|
|
|
|
|
2018-01-23 19:59:01 +01:00
|
|
|
const common = {
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.tsx?$/,
|
|
|
|
use: "ts-loader",
|
2018-09-12 19:12:44 +02:00
|
|
|
exclude: /node_modules\/(?!(@bitwarden)\/).*/,
|
2018-01-23 19:59:01 +01:00
|
|
|
},
|
2018-09-12 19:12:44 +02:00
|
|
|
],
|
2018-01-23 19:59:01 +01:00
|
|
|
},
|
|
|
|
plugins: [],
|
|
|
|
resolve: {
|
|
|
|
extensions: [".tsx", ".ts", ".js"],
|
2021-06-07 19:26:36 +02:00
|
|
|
plugins: [new TsconfigPathsPlugin({ configFile: "./tsconfig.json" })],
|
2018-01-23 19:59:01 +01:00
|
|
|
},
|
2021-06-10 18:50:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const prod = {
|
|
|
|
output: {
|
|
|
|
filename: "[name].js",
|
|
|
|
path: path.resolve(__dirname, "build"),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const dev = {
|
2018-01-23 19:59:01 +01:00
|
|
|
output: {
|
|
|
|
filename: "[name].js",
|
2018-09-12 19:12:44 +02:00
|
|
|
path: path.resolve(__dirname, "build"),
|
2021-06-07 20:50:56 +02:00
|
|
|
devtoolModuleFilenameTemplate: "[absolute-resource-path]",
|
2018-09-12 19:12:44 +02:00
|
|
|
},
|
2021-06-07 20:50:56 +02:00
|
|
|
devtool: "cheap-source-map",
|
2021-06-10 18:50:59 +02:00
|
|
|
};
|
2018-01-23 19:59:01 +01:00
|
|
|
|
|
|
|
const main = {
|
2021-06-10 18:50:59 +02:00
|
|
|
mode: NODE_ENV,
|
2018-01-23 19:59:01 +01:00
|
|
|
target: "electron-main",
|
|
|
|
node: {
|
|
|
|
__dirname: false,
|
2018-09-12 19:12:44 +02:00
|
|
|
__filename: false,
|
2018-01-23 19:59:01 +01:00
|
|
|
},
|
|
|
|
entry: {
|
2020-12-29 20:53:29 +01:00
|
|
|
main: "./src/entry.ts",
|
2018-01-23 19:59:01 +01:00
|
|
|
},
|
2018-09-14 21:55:55 +02:00
|
|
|
optimization: {
|
|
|
|
minimize: false,
|
|
|
|
},
|
2018-01-23 19:59:01 +01:00
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.node$/,
|
2018-09-12 19:12:44 +02:00
|
|
|
loader: "node-loader",
|
2021-04-23 10:45:30 +02:00
|
|
|
},
|
2018-01-23 19:59:01 +01:00
|
|
|
],
|
2021-12-20 15:47:17 +01:00
|
|
|
},
|
2018-01-23 19:59:01 +01:00
|
|
|
plugins: [
|
2021-04-23 10:45:30 +02:00
|
|
|
new CopyWebpackPlugin({
|
|
|
|
patterns: [
|
|
|
|
"./src/package.json",
|
|
|
|
{ from: "./src/images", to: "images" },
|
|
|
|
{ from: "./src/locales", to: "locales" },
|
2021-12-20 15:47:17 +01:00
|
|
|
],
|
|
|
|
}),
|
2022-09-01 22:08:47 +02:00
|
|
|
new EnvironmentPlugin({
|
|
|
|
FLAGS: envConfig.flags,
|
|
|
|
DEV_FLAGS: NODE_ENV === "development" ? envConfig.devFlags : {},
|
|
|
|
}),
|
2021-12-20 15:47:17 +01:00
|
|
|
],
|
2022-01-12 11:32:02 +01:00
|
|
|
externals: {
|
|
|
|
"electron-reload": "commonjs2 electron-reload",
|
2024-07-01 15:19:29 +02:00
|
|
|
"@bitwarden/desktop-napi": "commonjs2 @bitwarden/desktop-napi",
|
2024-02-26 23:31:09 +01:00
|
|
|
|
|
|
|
argon2: "commonjs2 argon2",
|
2022-01-12 11:32:02 +01:00
|
|
|
},
|
2018-01-23 19:59:01 +01:00
|
|
|
};
|
|
|
|
|
2021-06-10 18:50:59 +02:00
|
|
|
module.exports = merge(common, NODE_ENV === "development" ? dev : prod, main);
|