Skip to content

Instantly share code, notes, and snippets.

@mistakster
Last active April 6, 2017 10:27
Show Gist options
  • Save mistakster/0b78f3c022901e78c39806c3157ce0c8 to your computer and use it in GitHub Desktop.
Save mistakster/0b78f3c022901e78c39806c3157ce0c8 to your computer and use it in GitHub Desktop.
The platform independent way to provide environment variables inside “npm scripts” section
const ENV = process.env.NODE_ENV;
{
"name": "run-scripts",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack",
"build:release": "cross-env NODE_ENV=production webpack",
"build:debug": "cross-env NODE_ENV=development webpack"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"cross-env": "^4.0.0",
"webpack": "^2.3.3"
}
}
const webpack = require('webpack');
module.exports = {
entry: {
main: './index.js'
},
output: {
path: __dirname + '/public',
filename: '[name].js'
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
})
]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment