PatrickJS-starter icon indicating copy to clipboard operation
PatrickJS-starter copied to clipboard

Changing NODE_ENV or HOST variables in webpack from npm command line

Open gaurav2887 opened this issue 10 years ago • 1 comments

I want to use webpack.dev.js file for both development on my local machine and for AWS.

I want to write some logic in my service based on the ENV or host. e.g.

if(process.env.HOST=== 'localhost'){
 -- Add some headers here
}else{

--- Do not add headers
}

My configuration for webpack.dev.js is :

const ENV = process.env.ENV = process.env.NODE_ENV = 'development';
const HOST = process.env.HOST || 'localhost';

How can I change NODE_ENV or HOST when doing the build using 'webpack --config config/webpack.dev.js --progress --profile' so that variable can be development for local machine but it can be changed to devaws when I am building using npm run build:dev?

gaurav2887 avatar Sep 24 '16 00:09 gaurav2887

I use cross-env to set the NODE_ENV in my npm scripts: https://www.npmjs.com/package/cross-env

alsoicode avatar Aug 08 '17 15:08 alsoicode