Skip to content

Commit 9d75485

Browse files
committed
build: bundle preloads with esbuild instead of webpack
webpack was used only to bundle the 12 Electron preload scripts. esbuild does the same job with electron kept external and local imports inlined, and drops webpack plus webpack-cli from devDeps (gone from the lockfile, not even transitively). Note: AI-assisted (Claude Code). Manually verified by building: all 12 build/out/main/*/preload.js bundle with electron external and no leftover relative requires, yarn why webpack is empty, and the e2e suite passes so the preloads load and expose electronAPI at runtime.
1 parent fbe50e7 commit 9d75485

4 files changed

Lines changed: 214 additions & 552 deletions

File tree

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"type-check": "tsc --noEmit",
1818
"build": "tsc && yarn bundle:preload && node ./scripts/extract.js && node ./scripts/copyassets.js",
1919
"build:all": "yarn clean && yarn build && yarn start",
20-
"bundle:preload": "webpack --config webpack.preload.js",
20+
"bundle:preload": "node scripts/bundle-preload.js",
2121
"extract": "node scripts/extract.js",
2222
"pack": "yarn build && electron-builder --dir",
2323
"dist": "yarn build && electron-builder",
@@ -211,8 +211,7 @@
211211
"typescript": "^6.0.0",
212212
"typescript-eslint": "^8.61.1",
213213
"vitest": "^4.1.9",
214-
"webpack": "^5.107.2",
215-
"webpack-cli": "^4.5.0"
214+
"esbuild": "^0.28.1"
216215
},
217216
"resolutions": {
218217
"serialize-javascript": "^6.0.2",

scripts/bundle-preload.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) Jupyter Development Team.
2+
// Distributed under the terms of the Modified BSD License.
3+
4+
// Bundles the imports in the compiled preload.js files, since import/require of
5+
// local modules is not allowed in a sandboxed Electron preload at runtime. Each
6+
// preload is bundled in place; electron is kept external (the runtime provides
7+
// it). Replaces the previous webpack config.
8+
const esbuild = require('esbuild');
9+
10+
const preloadPrefix = 'build/out/main';
11+
const preloadFiles = [
12+
'aboutdialog/preload.js',
13+
'authdialog/preload.js',
14+
'dialog/preload.js',
15+
'labview/preload.js',
16+
'settingsdialog/preload.js',
17+
'progressview/preload.js',
18+
'pythonenvdialog/preload.js',
19+
'pythonenvselectpopup/preload.js',
20+
'remoteserverselectdialog/preload.js',
21+
'titlebarview/preload.js',
22+
'updatedialog/preload.js',
23+
'welcomeview/preload.js'
24+
];
25+
26+
esbuild
27+
.build({
28+
entryPoints: preloadFiles.map(file => `${preloadPrefix}/${file}`),
29+
outdir: preloadPrefix,
30+
outbase: preloadPrefix,
31+
bundle: true,
32+
platform: 'node',
33+
format: 'cjs',
34+
target: 'node20',
35+
external: ['electron'],
36+
allowOverwrite: true,
37+
logLevel: 'warning'
38+
})
39+
.catch(() => process.exit(1));

webpack.preload.js

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)