In my webpack.config.ts
, I export two configurations.
export default [development, production]
However, when I run webpack watch
, the production
config is rebuilt, and I'd like to avoid that.
How can I watch for only one of the two exported configurations?
CodePudding user response:
export default (env, argv) => [development, production]
export default (env: { WEBPACK_WATCH: boolean }) =>
env.WEBPACK_WATCH ? development : [development, production]
CodePudding user response:
You can use webpack command line environment option --env.
For example:
You can create 2 commands in scripts in package.json file.
"scripts": {
"start": "webpack --env development",
"build": "webpack --env production"
}
And in webpack.config.js file you can access them as follows:
module.exports = (env) => {
// ...
watch: env === 'development';
};