uniapp怎么配置生产环境
时间: 2023-06-24 07:08:06 浏览: 66
首先,在Uniapp项目的根目录下,找到 `manifest.json` 文件。在该文件中,可以定义不同环境下的配置参数。
例如,我们可以定义两个环境:开发环境和生产环境。在 `manifest.json` 文件中,可以添加以下代码:
```
"mp-weixin": {
"appid": "xxxxxxxxxxxxx",
"miniprogramRoot": "dist",
"pages": [
"pages/index/index",
"pages/about/about"
],
"window": {
"backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "xxx",
"navigationBarTextStyle": "black"
},
"env": {
"development": {
"BASE_API": "http://localhost:3000/api"
},
"production": {
"BASE_API": "https://api.example.com"
}
}
}
```
在上述代码中,`env` 属性定义了两个环境:`development` 和 `production`。在 `development` 环境中,`BASE_API` 的值为 `"http://localhost:3000/api"`,而在 `production` 环境中,`BASE_API` 的值为 `"https://api.example.com"`。
接下来,在项目中使用这个参数,可以通过 `process.env.BASE_API` 来获取它的值。例如:
```
axios.get(process.env.BASE_API + '/users')
```
最后,在打包时,可以通过以下命令来指定打包的环境:
```
npm run build --mode production
```
这样就可以根据不同的环境,配置不同的参数了。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)