-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
201 lines (194 loc) · 5.08 KB
/
webpack.config.js
File metadata and controls
201 lines (194 loc) · 5.08 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/**
* Unified webpack configuration for electron-builder
* Builds main process, preload script, and renderer
*/
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const isProduction = process.env.NODE_ENV === 'production';
// Common configuration shared across all builds
const commonConfig = {
mode: isProduction ? 'production' : 'development',
devtool: isProduction ? false : 'source-map',
resolve: {
extensions: ['.js', '.ts', '.jsx', '.tsx', '.json'],
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: {
loader: 'ts-loader',
options: {
transpileOnly: true,
},
},
},
],
},
};
// Main process configuration
const mainConfig = {
...commonConfig,
target: 'electron-main',
entry: './src/main/index.ts',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'main.js',
},
node: {
__dirname: false,
__filename: false,
},
plugins: [
// Inject the entry point constants that electron-forge normally provides
new webpack.DefinePlugin({
// Use path.join with __dirname for cross-platform compatibility
// __dirname in packaged app points to the app.asar/dist directory
// In dev mode, also use file:// since we don't run a dev server
MAIN_WINDOW_WEBPACK_ENTRY: isProduction
? '`file://${require("path").join(__dirname, "renderer", "index.html")}`'
: JSON.stringify(`file://${path.resolve(__dirname, 'dist/renderer/index.html')}`),
MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY: isProduction
? 'require("path").join(__dirname, "preload.js")'
: JSON.stringify(path.resolve(__dirname, 'dist/preload.js')),
}),
],
// Don't bundle electron
externals: {
electron: 'commonjs electron',
},
};
// Preload script configuration
const preloadConfig = {
...commonConfig,
target: 'electron-preload',
entry: './src/main/preload.ts',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'preload.js',
},
};
// Renderer process configuration
const rendererConfig = {
...commonConfig,
target: 'web', // Use 'web' target for renderer with context isolation
entry: './src/renderer/index.tsx',
output: {
path: path.resolve(__dirname, 'dist/renderer'),
filename: '[name].js',
chunkFilename: '[name].js',
publicPath: './',
},
resolve: {
...commonConfig.resolve,
// Provide fallbacks for Node.js modules used by zubridge
fallback: {
path: false,
fs: false,
os: false,
crypto: false,
buffer: false,
stream: false,
util: false,
assert: false,
http: false,
https: false,
zlib: false,
url: false,
querystring: false,
},
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: {
loader: 'ts-loader',
options: {
transpileOnly: true,
// Override tsconfig module to preserve ES imports for tree-shaking
compilerOptions: {
module: 'ESNext',
},
},
},
},
// Global CSS (non-module)
{
test: /\.css$/,
exclude: /\.module\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
// CSS Modules
{
test: /\.module\.css$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
modules: {
localIdentName: isProduction
? '[hash:base64:8]'
: '[name]__[local]--[hash:base64:5]',
},
},
},
],
},
{
test: /\.(png|svg|jpg|jpeg|gif|ico)$/i,
type: 'asset/resource',
},
],
},
optimization: {
usedExports: true,
sideEffects: true,
splitChunks: {
chunks: 'all',
cacheGroups: {
// Split React and related libraries into a separate vendor chunk
react: {
test: /[\\/]node_modules[\\/](react|react-dom|scheduler)[\\/]/,
name: 'vendor-react',
chunks: 'all',
priority: 20,
},
// Split FontAwesome into a separate chunk (it's large)
fontawesome: {
test: /[\\/]node_modules[\\/]@fortawesome[\\/]/,
name: 'vendor-fontawesome',
chunks: 'all',
priority: 15,
},
// Other vendors
vendors: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all',
priority: 10,
},
},
},
},
performance: {
maxAssetSize: 250 * 1024,
maxEntrypointSize: 300 * 1024,
},
plugins: [
new HtmlWebpackPlugin({
template: './src/renderer/index.html',
filename: 'index.html',
}),
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[name].css',
}),
],
};
module.exports = [mainConfig, preloadConfig, rendererConfig];