-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathwebpack.main.config.js
More file actions
110 lines (108 loc) · 3.95 KB
/
webpack.main.config.js
File metadata and controls
110 lines (108 loc) · 3.95 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* eslint-disable @typescript-eslint/no-var-requires */
const CopyPlugin = require("copy-webpack-plugin");
const webpack = require("webpack");
const path = require("path");
const relocateLoader = require("@vercel/webpack-asset-relocator-loader");
const AssetRelocatorPatch = require("@electron-forge/plugin-webpack/dist/util/AssetRelocatorPatch");
const isProduction = process.argv[process.argv.indexOf("--mode") + 1] === "production";
const isVerbose = process.env.WEBPACK_VERBOSE === "1";
module.exports = {
infrastructureLogging: {
level: isVerbose ? "verbose" : "warn",
},
stats: isVerbose ? "verbose" : "errors-warnings",
/**
* This is the main entry point for your application, it's the first file
* that runs in the main process.
*/
entry: "./src/index.ts",
// Put your normal webpack config below here
module: {
rules: require("./webpack.rules"),
},
resolve: {
extensions: [".js", ".ts", ".jsx", ".tsx", ".css", ".json"],
alias: {
// "@": path.resolve(__dirname, "./"),
},
},
optimization: {
// Simpler optimization for main process
splitChunks: {
chunks: "async", // Only split async chunks to avoid conflicts
cacheGroups: {
default: false, // Disable default cache group
vendors: false, // Disable vendor cache group for main process
},
},
// Enable tree shaking
usedExports: true,
sideEffects: true,
},
externals: {
// Externalize large schema files to load them dynamically
"../schema/schema_wh3.json": "commonjs2 ../schema/schema_wh3.json",
"../schema/schema_wh2.json": "commonjs2 ../schema/schema_wh2.json",
"../schema/schema_3k.json": "commonjs2 ../schema/schema_3k.json",
"../schema/schema_att.json": "commonjs2 ../schema/schema_att.json",
"../schema/schema_troy.json": "commonjs2 ../schema/schema_troy.json",
"../schema/schema_ph.json": "commonjs2 ../schema/schema_ph.json",
"../schema/schema_ph_dyn.json": "commonjs2 ../schema/schema_ph_dyn.json",
"../schema/schema_wh3.json.zst": "../schema/schema_wh3.json.zst",
"../schema/schema_wh2.json.zst": "../schema/schema_wh2.json.zst",
"../schema/schema_3k.json.zst": "../schema/schema_3k.json.zst",
"../schema/schema_att.json.zst": "../schema/schema_att.json.zst",
"../schema/schema_troy.json.zst": "../schema/schema_troy.json.zst",
"../schema/schema_ph.json.zst": "../schema/schema_ph.json.zst",
"../schema/schema_ph_dyn.json.zst": "../schema/schema_ph_dyn.json.zst",
},
plugins: [
new webpack.IgnorePlugin({ resourceRegExp: /^@aws-sdk\/client-s3$/ }),
new CopyPlugin({
patterns: [
{ from: "./temp/sub.js", to: "sub.js" },
{ from: "./locales/**/*" },
{ from: "./steamworks/**/*", to: "../" },
{ from: "./temp/readPacksWorker.js", to: "readPacksWorker.js" },
{ from: "./schema/**/*", to: "../schema/[name][ext]" },
{ from: "./node_modules/binary-file", to: "../node_modules/binary-file" },
{ from: "./node_modules/denodeify", to: "../node_modules/denodeify" },
],
}),
{
apply(compiler) {
compiler.hooks.compilation.tap("webpack-asset-relocator-loader", (compilation) => {
relocateLoader.initAssetCache(compilation, "native_modules");
});
},
},
],
output: {
pathinfo: false,
// Use unique chunk naming to avoid conflicts
chunkFilename: isProduction ? "main.[name].[contenthash].js" : "main.[name].js",
filename: "index.js", // Explicit main filename
// Clean output directory
clean: isProduction,
},
devServer: {
devMiddleware: {
writeToDisk: true,
},
hot: true,
},
devtool: isProduction ? "source-map" : "inline-source-map",
cache: {
type: "filesystem",
// Improve cache invalidation
buildDependencies: {
config: [__filename],
},
},
// Performance optimizations
performance: {
hints: isProduction ? "warning" : false,
maxEntrypointSize: 512000,
maxAssetSize: 512000,
},
};