-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebpack.electron.config.js
93 lines (89 loc) · 3.31 KB
/
webpack.electron.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import path, { dirname } from "path";
import webpack from "webpack";
import TerserPlugin from "terser-webpack-plugin";
import CopyPlugin from "copy-webpack-plugin";
import { BundleAnalyzerPlugin } from "webpack-bundle-analyzer";
import { fileURLToPath } from "url";
import ModuleScopePlugin from "@k88/module-scope-plugin";
export default (isLiveBuild, buildInfo, minify = false, analyze = false) =>
{
const __dirname = dirname(fileURLToPath(import.meta.url));
const plugins = [
new webpack.BannerPlugin({
"entryOnly": true,
"footer": true,
"raw": true,
"banner": "var CABLES = CABLES || { \"ELECTRON\": {}}; CABLES.ELECTRON = CABLES.ELECTRON || {}; CABLES.ELECTRON.build = " + JSON.stringify(buildInfo) + ";"
}),
new CopyPlugin({
"patterns": [
{
"from": path.resolve("./src_client", "renderer.js"),
"to": path.resolve("./dist", "public", "js", "buildinfo.json"),
"transform": () =>
{
if (!buildInfo.platform)
{
buildInfo.platform = {};
}
if (process.env.BUILD_VERSION)
{
buildInfo.version = process.env.BUILD_VERSION;
}
if (process.env.BUILD_OS)
{
buildInfo.platform.os = process.env.BUILD_OS;
}
if (process.env.npm_config_npm_version)
{
buildInfo.platform.npm = process.env.npm_config_npm_version;
}
if (process.env.npm_package_engines_node)
{
buildInfo.platform.node = process.env.npm_package_engines_node;
}
return JSON.stringify(buildInfo);
}
},
],
})
];
if (analyze)
{
const analyzeOptions = {
"analyzerMode": "static",
"openAnalyzer": false,
"reportTitle": "cables electron",
"reportFilename": path.join(__dirname, "dist", "report_electron.html")
};
plugins.push(new BundleAnalyzerPlugin(analyzeOptions));
}
return {
"mode": isLiveBuild ? "production" : "development",
"devtool": minify ? "source-map" : false,
"entry": {
"scripts.electron.js": [path.resolve("./src_client", "renderer.js")],
},
"output": {
"path": path.resolve("./dist", "public", "js"),
"filename": "[name]",
},
"optimization": {
"concatenateModules": true,
"minimizer": [new TerserPlugin({
"extractComments": false,
"terserOptions": { "output": { "comments": false } }
})],
"minimize": minify,
"usedExports": true
},
"externals": ["CABLES"],
"resolve": {
"extensions": [".js"],
"plugins": [
new ModuleScopePlugin.default("src_client/"),
],
},
"plugins": plugins
};
};