"scripts": { "dev": "cross-env NODE_ENV=development nuxt", "pro": "cross-env NODE_ENV=production nuxt", "pre": "cross-env NODE_ENV=prerelease nuxt", "build-prod": "cross-env NODE_ENV=production nuxt build", "build-prer": "cross-env NODE_ENV=prerelease nuxt build", "build-test": "cross-env NODE_ENV=development nuxt build", "start": "nuxt start", "generate": "nuxt generate" },
本地開發環境javascript
dev環境
"dev": "cross-env NODE_ENV=development nuxt"vue
預生產環境
"pre": "cross-env NODE_ENV=prerelease nuxt",java
生產環境
"pro": "cross-env NODE_ENV=production nuxt"ios
Prod上線 環境篇 命令行(num run build)json
測試版上線打包
"build-test": "cross-env NODE_ENV=development nuxt build",axios
預生產上線打包
"build-prer": "cross-env NODE_ENV=prerelease nuxt build",api
生產版上線打包
"build-prod": "cross-env NODE_ENV=production nuxt build",跨域
1.本地環境Axios請求的配置服務器
process.env.NODE_ENV 就是咱們定義變量
if (process.env.NODE_ENV == 'production') { //線上 axios.defaults.baseURL = "https:xxx.xxx.xxx" } else if (process.env.NODE_ENV == 'development') { //本地 axios.defaults.baseURL = 'http://192.168.1.1:80' } else { //預發佈 axios.defaults.baseURL = 'http://xxx.xxx.1.1:80' // }
線上環境的請求配置測試
特別說明一下VueCli3.x 的環境配置 須要本身在根目錄新建.env.development 或者.env.production 文件
// .env.development NODE_ENV = 'development' VUE_APP_CURRENTMODE = 'dev' VUE_APP_BASEURL = '本地開發api地址' //例如 VUE_APP_BASE_API='192.xxx.xxx.1:80'
module.exports = { // 修改的配置 // 將baseUrl: '/api',改成baseUrl: '/', baseUrl: '/', devServer: { proxy: { '/api': { target: 'http://www.example.org', changeOrigin: true, ws: true, pathRewrite: { '^/api': '' } } } } }