I have a webpack config that is setup to watch for changes.
Once in a while, I would like to just run the build one time and then exit.
I solve this now by typing npm run dev
(which runs webpack --config <config.json>
), and then hit Ctrl+C
when it's done with the first build cycle.
Is there a command line switch that I can use to overrule the watch setting from the config? Something like an negated --watch
switch? A --do-not-watch
option?
@Vegar, I know this a little older, but i would like to submit some code for those that are still finding this.
Here's an example of flagging the watch property in webpack.config.js based on the presence of something in the command:
module.exports = {
//...
watch: (process.argv.indexOf('--watch') > -1)
//...
}
...then we add our variations in package.json:
{
"scripts": {
"build": "webpack --config webpack.config.js --mode='production'",
"watch": "webpack --config webpack.config.js --mode='production' --watch"
}
}
...allowing us to build once:
$ npm run build
...or watch continuously:
$ npm run watch
Found this issue 5 minutes to late:
https://github.com/webpack/webpack/issues/2819
So basically, no - there ain't no such switch, but it's easy to add an 'if' in your config based on content of the process.argv
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With