cross-env NODE_ENV=development role

What cross-env does:
it runs scripts that set and use environment variables across platforms

When we use NODE_ENV=production
to set the environment variable, most windows commands will prompt that it will block or abnormal, or, windows does not support such a setting method of NODE_ENV=development, and will report an error. Hence
the cross-env. We can use the cross-env command so we don't have to worry about platform settings or using environment variables. That is to say, cross-env
can provide a script for setting environment variables, so that we can set environment variables in unix way, but it is also compatible on windows.

cross-env installation: (development only use --save-dev)

npm install:
npm install cross-env --save-dev
yarn install:
yarn add cross-env --dev

NODE_ENV=development/productionIt is to configure environment variables during packaging to distinguishdevelopment environment/Formal environment
Use as follows:

"scripts" :  { 
  "dev" :  "NODE_ENV=development webpack-dev-server --progress --colors --devtool cheap-module-eval-source-map --hot --inline" , 
  "build" :  "NODE_ENV =production webpack --progress --colors --devtool cheap-module-source-map" , 
  "build:dll" :  "webpack --config webpack.dll.config.js" 
} ,
  • 1
  • 2
  • 3
  • 4
  • 5

The above code is not compatible in the window / mac environment. Windows does not support such a setting method of NODE_ENV=development, so the cross-env library needs to be introduced to achieve compatibility:

"scripts" :  { 
  "dev" :  "cross-env NODE_ENV=development webpack-dev-server --progress --colors --devtool cheap-module-eval-source-map --hot --inline" , 
  "build" :  "cross-env NODE_ENV=production webpack --progress --colors --devtool cheap-module-source-map" , 
  "build:dll" :  "webpack --config webpack.dll.config.js" 
}
  • 1
  • 2
  • 3
  • 4
  • 5

Related: cross-env NODE_ENV=development role