-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.workers.config.js
77 lines (67 loc) · 2.26 KB
/
webpack.workers.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const webpackMain = require("electron-webpack/webpack.main.config");
const webpack = require("webpack");
const webpackCommonConfig = require("./webpack.common.config");
const { glob } = require("glob");
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const workers = glob
.sync("./src/main/**/*.worker.ts")
.map((filePath) => {
const name = path.basename(filePath, path.extname(filePath));
return [name, path.dirname(filePath).split("src/main/")[1], filePath];
})
.reduce((acc, [name, directoryPath, filePath]) => {
acc[path.join(directoryPath, name)] = filePath;
return acc;
}, {});
module.exports = async (
/** @type {import("electron-webpack/out/core").ConfigurationEnv} */ env = {}
) => {
console.info("Compile workers", workers);
env.production = true;
env.autoClean = false;
const config = await webpackMain(env);
if (!config) {
throw new Error("No main config found for workers.");
}
config.mode = "production";
for (const plugin of config.plugins) {
if (plugin instanceof webpack.BannerPlugin) {
plugin.options.exclude = /(\.worker)\.js$/i;
}
if (plugin instanceof HtmlWebpackPlugin) {
plugin.options?.excludeChunks?.push(...Object.keys(workers));
}
}
config.module.rules.push({
loader: "string-replace-loader",
options: {
replace: `require("path").resolve(process.env.ELECTRON_NATIVES_PATH, "classic-level/")`,
search: "__dirname",
},
test: /node_modules\/classic-level\/binding\.js$/,
});
const shouldNotBeExternal = [
"@lsagetlethias/tstrait",
"@socialgouv/archimail-pst-extractor",
"classic-level",
"electron-log",
"electron-store",
"electron-util",
"i18next",
"lodash",
"posthog-js",
"posthog-node",
"source-map-support",
"tarn",
"uuid",
];
if (Array.isArray(config.externals)) {
config.externals = config.externals.filter(
(name) => !shouldNotBeExternal.includes(name)
);
}
config.entry = workers;
return webpackCommonConfig(config);
};
module.exports.workers = workers;