-
Notifications
You must be signed in to change notification settings - Fork 8
/
webpack.main.config.js
36 lines (31 loc) · 1.03 KB
/
webpack.main.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
const path = require("path");
const glob = require("glob");
const webpack = require("webpack");
const webpackCommonConfig = require("./webpack.common.config");
require("dotenv").config();
module.exports =
/** @param {import("webpack").Configuration} config */ function (config) {
const isProd = config.mode === "production";
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;
}, {});
if (isProd) {
for (const plugin of config.plugins) {
if (plugin instanceof webpack.BannerPlugin) {
plugin.options.exclude = /(preload|\.worker)\.js$/i;
}
}
}
config.entry = {
...config.entry,
...workers,
};
return webpackCommonConfig(config);
};