1. What is cross-env?
It is run cross-platform set and use environment variables ( environment variables Node in the script) is.
2. Why do we need cross-env?
We custom configuration environment variable, due to the different environments, configuration is different. In the example configuration environment variable window and linux.
2.1, configuration in window
#node中常用的到的环境变量是NODE_ENV,首先查看是否存在
set NODE_ENV
#如果不存在则添加环境变量
set NODE_ENV=production
#环境变量追加值 set 变量名=%变量名%;变量内容
set path=%path%;C:\web;C:\Tools
#某些时候需要删除环境变量
set NODE_ENV=
2.2 disposed in linux
#node中常用的到的环境变量是NODE_ENV,首先查看是否存在
echo $NODE_ENV
#如果不存在则添加环境变量
export NODE_ENV=production
#环境变量追加值
export path=$path:/home/download:/usr/local/
#某些时候需要删除环境变量
unset NODE_ENV
#某些时候需要显示所有的环境变量
env
3. What is the role of cross-env?
When we use NODE_ENV = production to set environment variables, most windows command prompt will block or exception, or, windows do not support how such NODE_ENV = development of error. Therefore, cross-env appeared. We can use cross-env command, so that we do not have to worry about the platform setting up or using environment variables. That cross-env provides a set environment variables scripts, so that we can set the environment variable to unix way, but on the windows can be compatible.
4, how to use the cross-env in the project?
npm install --save-dev cross-env
Then package.json command scripts are as follows below:
"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",
}