You can set environment variables in Windows with the "SET" command:
set NODE_ENV=production
And you can specify short scripts in a package.json file:
"scripts": {
    "buildDev": "set NODE_ENV=development && webpack",
    "buildProd": "set NODE_ENV=production && webpack",
}
These work perfectly except for one thing: the value of NODE_ENV when webpack begins executing my config file is "development " - note the trailing space.
This prevents my config file from detecting the correct environment (via process.env.NODE_ENV) and returning the appropriate configuration.
I managed to fix this by, funnily enough, removing the space:
"buildDev": "set NODE_ENV=development&& webpack"
which (to me at least) seems just wrong.  I expected this would have resulted in a syntax error and a NODE_ENV value of development&&, but it works perfectly - albeit being ugly.
Make it cross-platform by using cross-env:
"buildDev": "cross-env NODE_ENV=development webpack"
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