-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check for webpack binary path before proceeding to start the server
- Loading branch information
Showing
1 changed file
with
18 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,24 @@ | ||
#!/usr/bin/env node | ||
|
||
const path = require('path'); | ||
const { spawn } = require('child_process'); | ||
const fs = require('fs') | ||
const path = require('path') | ||
const { spawn } = require('child_process') | ||
|
||
const webpackConfig = path.resolve(__dirname, 'webpack.config.js') | ||
const webpackConfigPath = path.resolve(__dirname, 'webpack.config.js') | ||
let webpackBinPath = path.resolve(__dirname, 'node_modules/webpack/bin/webpack.js') | ||
|
||
spawn(`${__dirname}/node_modules/webpack/bin/webpack.js serve --config ${webpackConfig} --open`, [], { | ||
if (!fs.existsSync(webpackBinPath)) { | ||
// when using newer versions of npx, node modules are not inside swift-react folder | ||
webpackBinPath = path.resolve(__dirname, '../webpack/bin/webpack.js') | ||
} | ||
|
||
if (!fs.existsSync(webpackBinPath)) { | ||
console.log(`\nCouldn't find webpack binary to start webpack server. Please raise an issue at https://github.com/mesaugat/swift-react/issues`) | ||
|
||
process.exit(1) | ||
} | ||
|
||
spawn(`${webpackBinPath} serve --config ${webpackConfigPath} --open`, [], { | ||
shell: true, | ||
stdio: 'inherit' | ||
}); | ||
}) |