-
Notifications
You must be signed in to change notification settings - Fork 528
Expand file tree
/
Copy pathprepublish.mjs
More file actions
35 lines (28 loc) · 1.13 KB
/
prepublish.mjs
File metadata and controls
35 lines (28 loc) · 1.13 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
#!/usr/bin/env node
// Skip webpack if SKIP_WEBPACK environment variable is set to 'true'
if (process.env.SKIP_WEBPACK === 'true') {
console.log('Skipping webpack compilation (SKIP_WEBPACK=true)');
process.exit(0);
}
// Otherwise, run webpack using the local webpack-cli installation
const { spawn } = await import('child_process');
const { fileURLToPath } = await import('url');
const { dirname, resolve, join } = await import('path');
const scriptFilename = fileURLToPath(import.meta.url);
const scriptDirname = dirname(scriptFilename);
const projectRoot = resolve(scriptDirname, '..');
// Use webpack-cli from local node_modules (cross-platform)
const webpackCliPath = join(projectRoot, 'node_modules', '.bin', 'webpack');
const isWindows = process.platform === 'win32';
const webpackCommand = isWindows ? `${webpackCliPath}.cmd` : webpackCliPath;
const webpack = spawn(webpackCommand, ['--mode', 'production'], {
stdio: 'inherit',
cwd: projectRoot
});
webpack.on('close', (code) => {
process.exit(code || 0);
});
webpack.on('error', (error) => {
console.error('Error running webpack:', error);
process.exit(1);
});