Skip to content

Instantly share code, notes, and snippets.

@nchase
Created January 23, 2017 15:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nchase/087a49584ee04e454728804511f67697 to your computer and use it in GitHub Desktop.
Save nchase/087a49584ee04e454728804511f67697 to your computer and use it in GitHub Desktop.
Webpack EnvironmentPlugin
// Webpack's poorly-documented EnvironmentPlugin
//
// Read more here: https://github.com/webpack/webpack/blob/master/lib/EnvironmentPlugin.js
var webpack = require('webpack');
module.exports = {
plugins: [
new webpack.EnvironmentPlugin([
'NODE_ENV'
])
]
}
@nchase
Copy link
Author

nchase commented Jan 23, 2017

with this, you should be able to pass your NODE_ENV to the webpack build process (e.g. NODE_ENV=production webpack) and in your code, you can use process.env.NODE_ENV to decide what to do differently based on the value of NODE_ENV.

@floweb
Copy link

floweb commented Jan 27, 2017

Just wanted to thank you for this, I wonder why this is not more popular tho!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment