Reputation: 66480
Is it possible to have one variables that will be different on dev and production environments. What should I use to make that variable. Is testing for location url a good solution?
Upvotes: 1
Views: 190
Reputation: 7900
In your package.json
file, you can set environment variables in the
script
section, like NODE_ENV=production
for the build
script in this example:
{
"scripts": {
"start": "npm run dev",
"dev": "./node_modules/.bin/webpack-dev-server ...",
"build": "NODE_ENV=production ./node_modules/.bin/webpack -p --config webpack.production.config.js"
} ... }
Then, in your Javascript code you can test for it using the process
global:
if (process.env.NODE_ENV === 'production') { ... } else { ... }
Hope this helps.
Upvotes: 2