Skip to content

Commit 236a0d5

Browse files
committed
build: avoid calling webpack for each platform build
Signed-off-by: Fred Bricon <fbricon@gmail.com>
1 parent d966c74 commit 236a0d5

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

.github/workflows/release.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,21 @@ jobs:
134134
echo "publishPreReleaseFlag=--pre-release" >> $GITHUB_ENV
135135
- name: Package vscode-java
136136
run: |
137+
# Compile JavaScript once (webpack is platform-independent)
138+
npm run vscode:prepublish
139+
140+
# Set flag to skip webpack during vsce package (webpack already ran above)
141+
export SKIP_WEBPACK=true
142+
143+
# Package for each platform (only downloads JDK and creates VSIX, no recompilation)
137144
platforms=("win32-x64" "win32-arm64" "linux-x64" "linux-arm64" "darwin-x64" "darwin-arm64")
138145
for platform in ${platforms[@]}; do
139146
npm run download-jre -- --target ${platform} --javaVersion 21
140147
vsce package ${{ env.publishPreReleaseFlag }} --target ${platform} -o java-${platform}-${{ env.EXT_VERSION }}-${GITHUB_RUN_NUMBER}.vsix
141148
done
142149
rm -rf jre/
143150
vsce package ${{ env.publishPreReleaseFlag }} -o vscode-java-${{ env.EXT_VERSION }}-${GITHUB_RUN_NUMBER}.vsix
151+
144152
ls -lash *.vsix
145153
- name: Upload VSIX Artifacts
146154
uses: actions/upload-artifact@v5

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2020,7 +2020,7 @@
20202020
}
20212021
},
20222022
"scripts": {
2023-
"vscode:prepublish": "webpack --mode production",
2023+
"vscode:prepublish": "node scripts/prepublish.mjs",
20242024
"compile": "tsc -p ./&webpack --mode development",
20252025
"watch": "webpack --mode development --watch",
20262026
"pretest": "npm run compile",

scripts/prepublish.mjs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env node
2+
3+
// Skip webpack if SKIP_WEBPACK environment variable is set to 'true'
4+
if (process.env.SKIP_WEBPACK === 'true') {
5+
console.log('Skipping webpack compilation (SKIP_WEBPACK=true)');
6+
process.exit(0);
7+
}
8+
9+
// Otherwise, run webpack using the local webpack-cli installation
10+
const { spawn } = await import('child_process');
11+
const { fileURLToPath } = await import('url');
12+
const { dirname, resolve, join } = await import('path');
13+
14+
const scriptFilename = fileURLToPath(import.meta.url);
15+
const scriptDirname = dirname(scriptFilename);
16+
const projectRoot = resolve(scriptDirname, '..');
17+
18+
// Use webpack-cli from local node_modules (cross-platform)
19+
const webpackCliPath = join(projectRoot, 'node_modules', '.bin', 'webpack');
20+
const isWindows = process.platform === 'win32';
21+
const webpackCommand = isWindows ? `${webpackCliPath}.cmd` : webpackCliPath;
22+
23+
const webpack = spawn(webpackCommand, ['--mode', 'production'], {
24+
stdio: 'inherit',
25+
cwd: projectRoot
26+
});
27+
28+
webpack.on('close', (code) => {
29+
process.exit(code || 0);
30+
});
31+
32+
webpack.on('error', (error) => {
33+
console.error('Error running webpack:', error);
34+
process.exit(1);
35+
});

0 commit comments

Comments
 (0)