NUXTJS的多环境配置
借助cross-env配置环境参数
package.json:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| {
"scripts": { "dev": "nuxt", "build": "cross-env PORT=3000 ROUTE_BASE=/ BASE_BROWSER_URL=/ BASE_SERVER_URL=http://172.17.0.1:9998/ NODE_ENV=production nuxt build", "start": "cross-env PORT=3000 ROUTE_BASE=/ BASE_BROWSER_URL=/ BASE_SERVER_URL=http://172.17.0.1:9998/ NODE_ENV=production nuxt start", "generate": "nuxt generate", "lint:js": "eslint --ext \".js,.vue\" --ignore-path .gitignore .", "lint": "yarn lint:js", "startTest": "cross-env PORT=4000 ROUTE_BASE=/ BASE_BROWSER_URL=/ BASE_SERVER_URL=http://172.17.0.1:9998/ NODE_ENV=production nuxt start", "buildTest": "cross-env PORT=4000 ROUTE_BASE=/ BASE_BROWSER_URL=/ BASE_SERVER_URL=http://172.17.0.1:9998/ NODE_ENV=production nuxt build" }
}
|
nuxt.config.js:
1 2 3 4 5 6
| { server: { port: process.env.PORT || 3000, host: '0.0.0.0' }, }
|
借助pm2的env配置
ecosystem.config.js:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| module.exports = { apps: [ { name: 'lcot-test', script: './node_modules/nuxt/bin/nuxt.js', args: 'start ./', env:{ PORT:4000, ROUTE_BASE:"/", BASE_BROWSER_URL:"/", BASE_SERVER_URL:"http://172.17.0.1:9998/", NODE_ENV:'production' } } ] }
|
-
Next Post
初识Ktorm
-
Previous Post
NuxtJS非根目录下部署