Sometimes it is necessary to differentiate between packages from production and development environments to determine which base url or other variables you need to useMethod 1:
//windows System:
"builddev": "set NODE_ENV=dev&&vue-cli-service build",
"buildprod": "set NODE_ENV=prod&&vue-cli-service build",
//mac System:
"builddev": "export NODE_ENV=dev&&vue-cli-service build",
"buildprod": "export NODE_ENV=prod&&vue-cli-service build",
Method 2:
First install the dependencies: NPM install –save-dev cross-env
Then configure compatible Windows and MAC environments
"builddev": "cross-env NODE_ENV=dev vue-cli-service build",
"buildprod": "cross-env NODE_ENV=prod vue-cli-service build",
Finally, in the JS code, the corresponding value can be obtained through: process.env.node_env, which is used to judge the environment:
baseurl:process.env.NODE_ENV===’prod’?’http://prod.api.com’:’http://test.api.com’
console.log(process.env);// {BASE_URL: “”, NODE_ENV:” prod “}
Ps: The vUE – CLi is used here to configure NODE_ENV, other projects may be to configure WEBPACK_ENV, directly replace, then console. Log (process.env) to see the environment
Read More:
- Vue-cli2 sub environment packaging
- JS uses onerror to automatically catch exceptions
- Module build failed: Error: Couldn’t find preset “es2015” relative to directory
- The addition, deletion and modification of DOM in JS Foundation
- Using for in loop complex data types (object and array) in ES6
- Solution to build error in Vue project (error in static/JS)/vendor.xxxxx.js from UglifyJs)
- JS to find the last character of the string and remove it
- How to introduce iconfont into uni-app
- JS to determine whether the string contains a character
- How to Set Time Zone in Golang
- Localstorage sets the expiration time.
- Solve the problem of repeatedly clicking the same route console in Vue to report an error
- [Weex]Error in creating project NPM: unable to load file D:\program files\nodejs\node_ global\ weex.ps1 Because scripts are not allowed to run on this system.
- How to Block a frame with origin from accessing a cross origin frame
- Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to crrent location: “/home“
- TypeScript error TS2345: Argument of type ‘String ‘is not assignable to parameter of type ‘string’
- How to Fix “HTTP 405 method not allowed” Error
- Openmv identifies two-dimensional code, color recognition and serial communication
- JS native implementation Promise.all
- VUE: How to Solve NPM Always Install Error