生活中的Design.

NUXTJS的多环境配置

字数统计: 230阅读时长: 1 min
2021/08/05 Share

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, // default: 3000
host: '0.0.0.0' // default: localhost,
},
}

借助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'
}
}
]
}
CATALOG
  1. 1. NUXTJS的多环境配置
    1. 1.0.1. 借助cross-env配置环境参数
    2. 1.0.2. 借助pm2的env配置