Closed pvorona closed 7 years ago
I like to use this trick for this kind of things : when you use npm scripts for running webpack it set "npm_lifecycle_event" to the npm script name.
$ npm run build
const ENV = process.env.npm_lifecycle_event
if(ENV === 'build'){
// production process
}
else{
// dev process
}
In Webpack 2, doing webpack -p
now sets NODE_ENV=production
, so I think checking for env is best done with process.env.NODE_ENV
. I've noted this now since I started adding in Webpack 2 notes.
In case you only want to set NODE_ENV, it is possible to pass it from env vars like this:
no need to use define plugin