-
Notifications
You must be signed in to change notification settings - Fork 8
/
webpack.renderer.config.js
63 lines (53 loc) · 1.59 KB
/
webpack.renderer.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
const webpackCommonConfig = require("./webpack.common.config");
const path = require("path");
const glob = require("glob");
const CopyWebpackPlugin = require("copy-webpack-plugin");
require("dotenv").config();
module.exports =
/** @param {import("webpack").Configuration} config */ function (config) {
const isProd = config.mode === "production";
const workers = glob
.sync("./src/renderer/**/*.fork.ts")
.map((filePath) => {
const name = path.basename(filePath, path.extname(filePath));
return [
name,
path.dirname(filePath).split("src/renderer/")[1],
filePath,
];
})
.reduce((acc, [name, directoryPath, filePath]) => {
acc[path.join(directoryPath, name)] = filePath;
return acc;
}, {});
if (isProd) {
if (!config.plugins?.length) {
config.plugins = [];
}
config.plugins.push(
new CopyWebpackPlugin({
patterns: [
{
from: "node_modules/fswin/electron",
to: "lib/fswin/electron",
},
{
from: "node_modules/fswin/node",
to: "lib/fswin/node",
},
],
})
);
}
config.entry = {
...config.entry,
...workers,
};
const finalConfig = webpackCommonConfig(config);
const findHtmlWebpackPlugin = (plugins) =>
plugins.find((plugin) => plugin?.options?.excludeChunks);
findHtmlWebpackPlugin(finalConfig.plugins)?.options?.excludeChunks?.push?.(
...Object.keys(workers)
);
return finalConfig;
};