cross-env
cross-env is a script that sets and uses environment variables across platforms.
Used in most Windows command linesNODE_ENV = production
An error will be reported when setting environment variables. Similarly, how Windows and Linux commands set environment variables are different.
Use cross-env to set the same NODE_ENV parameter on different platforms.
use
Install
npm install cross-env --save-dev "scripts": { "serve": "cross-env NODE_ENV=development vue-cli-service serve --open", "build": "cross-env NODE_ENV=production vue-cli-service build" }
development
production
Global variable with process node
Applicable scenarios
Suitable for scenarios where there are differences in local online environments. For example, the development domain name that is not used locally can be judged by NODE_ENV.
if(.NODE_ENV!='development'){ //Online environment}
Knowledge point extension: cross-env usage notes
Cross-env can set and use environment variables across platforms
In most cases, using it on Windows platform is similar to:NODE_ENV=production
The command line instructions will be stuck. There are many differences between Windows platform and POSIX when using command line (for example, in POSIX, use$ENV_VAR
,In windows, use %ENV_VAR%. . . )
cross-env makes it all simple, using unique instructions on different platforms, without worrying about cross-platform issues
npm installation method
npm i --save-dev cross-env
This is configured in npm scripts (mostly)
{ "scripts": { "build": "cross-env NODE_ENV=production webpack --config build/" } }
runnpm run build
, so that NODE_ENV is set successfully, no need to worry about cross-platform issues
Summarize
The above is the use of cross-env in vue introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!
If you think this article is helpful to you, please reprint it. Please indicate the source, thank you!