Skip to content

Commit

Permalink
Check for webpack binary path before proceeding to start the server
Browse files Browse the repository at this point in the history
  • Loading branch information
mesaugat committed May 29, 2021
1 parent 7971422 commit 96c0487
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions cli.js
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'
});
})

0 comments on commit 96c0487

Please sign in to comment.