Skip to content

Commit 96c0487

Browse files
committed
Check for webpack binary path before proceeding to start the server
1 parent 7971422 commit 96c0487

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

cli.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
#!/usr/bin/env node
22

3-
const path = require('path');
4-
const { spawn } = require('child_process');
3+
const fs = require('fs')
4+
const path = require('path')
5+
const { spawn } = require('child_process')
56

6-
const webpackConfig = path.resolve(__dirname, 'webpack.config.js')
7+
const webpackConfigPath = path.resolve(__dirname, 'webpack.config.js')
8+
let webpackBinPath = path.resolve(__dirname, 'node_modules/webpack/bin/webpack.js')
79

8-
spawn(`${__dirname}/node_modules/webpack/bin/webpack.js serve --config ${webpackConfig} --open`, [], {
10+
if (!fs.existsSync(webpackBinPath)) {
11+
// when using newer versions of npx, node modules are not inside swift-react folder
12+
webpackBinPath = path.resolve(__dirname, '../webpack/bin/webpack.js')
13+
}
14+
15+
if (!fs.existsSync(webpackBinPath)) {
16+
console.log(`\nCouldn't find webpack binary to start webpack server. Please raise an issue at https://github.com/mesaugat/swift-react/issues`)
17+
18+
process.exit(1)
19+
}
20+
21+
spawn(`${webpackBinPath} serve --config ${webpackConfigPath} --open`, [], {
922
shell: true,
1023
stdio: 'inherit'
11-
});
24+
})

0 commit comments

Comments
 (0)