详细问题描述
(DCloud产品不会有明显的bug,所以你遇到的问题大都是在特定环境下才能重现的问题,请仔细描述你的环境和重现方式,否则DCloud很难排查解决你的问题)
[内容]
重现步骤
[步骤]
增加
"scripts": {
"mp-weixin-test": {
"title": "微信小程序(test)",
"env": {
"NODE_ENV": "test",
"UNI_PLATFORM": "mp-weixin",
"BASE_API": "https://api-test.xxx.com"
},
"define": {
"MP-weixin": true
}
}
}
[结果]
main.js
console.log(process.env.NODE_ENV) //输出 development
console.log("api: " + process.env.BASE_API); // 输出 api: undefined
[期望]
main.js
console.log(process.env.NODE_ENV) //输出 test
console.log("api: " + process.env.BASE_API); // 输出 api: https://api-test.xxx.com
[如果语言难以表述清晰,拍一个视频或截图,有图有真相]
IDE运行环境说明
HBuilderX版本 [2.6.1.20200226]
> uni-cli-ts@0.1.0 info /Users/jimmy/MiniProjects/uni-cli-ts
> node node_modules/@dcloudio/vue-cli-plugin-uni/commands/info.js
uni-app v2.6.1
uni-app cli v2.0.0-26120200226001
Environment Info:
System:
OS: macOS 10.15.2
CPU: (8) x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
Binaries:
Node: 13.2.0 - /usr/local/bin/node
Yarn: 1.19.2 - /usr/local/bin/yarn
npm: 6.12.1 - /usr/local/bin/npm
Browsers:
Chrome: 80.0.3987.122
Firefox: 72.0.1
Safari: 13.0.4
npmPackages:
@dcloudio/types: * => 0.4.4
@dcloudio/uni-app-plus: ^2.0.0-26120200226001 => 2.0.0-26120200226001
@dcloudio/uni-app-plus-nvue: 0.0.1
@dcloudio/uni-app-plus-nvue-v8: 0.0.1
@dcloudio/uni-cli-shared: ^2.0.0-26120200226001 => 2.0.0-26120200226001
@dcloudio/uni-h5: ^2.0.0-26120200226001 => 2.0.0-26120200226001
@dcloudio/uni-helper-json: * => 1.0.5
@dcloudio/uni-migration: ^2.0.0-26120200226001 => 2.0.0-26120200226001
@dcloudio/uni-mp-alipay: ^2.0.0-26120200226001 => 2.0.0-26120200226001
@dcloudio/uni-mp-baidu: ^2.0.0-26120200226001 => 2.0.0-26120200226001
@dcloudio/uni-mp-qq: ^2.0.0-26120200226001 => 2.0.0-26120200226001
@dcloudio/uni-mp-toutiao: ^2.0.0-26120200226001 => 2.0.0-26120200226001
@dcloudio/uni-mp-weixin: ^2.0.0-26120200226001 => 2.0.0-26120200226001
@dcloudio/uni-stat: ^2.0.0-26120200226001 => 2.0.0-26120200226001
@dcloudio/uni-template-compiler: ^2.0.0-26120200226001 => 2.0.0-26120200226001
@dcloudio/vue-cli-plugin-hbuilderx: ^2.0.0-26120200226001 => 2.0.0-26120200226001
@dcloudio/vue-cli-plugin-uni: ^2.0.0-26120200226001 => 2.0.0-26120200226001
@dcloudio/vue-cli-plugin-uni-optimize: ^2.0.0-26120200226001 => 2.0.0-26120200226001
@dcloudio/webpack-uni-mp-loader: ^2.0.0-26120200226001 => 2.0.0-26120200226001
@dcloudio/webpack-uni-nvue-loader: 0.0.1
@dcloudio/webpack-uni-pages-loader: ^2.0.0-26120200226001 => 2.0.0-26120200226001
@vue/babel-helper-vue-jsx-merge-props: 1.0.0
@vue/babel-plugin-transform-vue-jsx: 1.1.2
@vue/babel-preset-app: 3.12.1
@vue/babel-preset-jsx: 1.1.2
@vue/babel-sugar-functional-vue: 1.1.2
@vue/babel-sugar-inject-h: 1.1.2
@vue/babel-sugar-v-model: 1.1.2
@vue/babel-sugar-v-on: 1.1.2
@vue/cli-overlay: 4.2.3
@vue/cli-plugin-babel: 3.5.1 => 3.5.1
@vue/cli-plugin-router: 4.2.3
@vue/cli-plugin-typescript: ^3.5.1 => 3.12.1
@vue/cli-plugin-vuex: 4.2.3
@vue/cli-service: ^4.2.0 => 4.2.3
@vue/cli-shared-utils: 3.12.1
@vue/component-compiler-utils: 3.1.1 (3.1.1)
@vue/preload-webpack-plugin: 1.1.1
@vue/web-component-wrapper: 1.2.0
mpvue-page-factory: 1.0.1
mpvue-template-compiler: 1.0.13
uni-h5-vue: 2.6.10
uni-mp-vue: 2.6.10
vue: ^2.6.11 => 2.6.11
vue-class-component: ^6.3.2 => 6.3.2 (7.2.3)
vue-hot-reload-api: 2.3.4
vue-loader: 15.9.0 (15.9.0)
vue-property-decorator: ^8.0.0 => 8.4.0
vue-router: 3.0.1
vue-style-loader: 4.1.2
vue-template-compiler: ^2.6.11 => 2.6.11
vue-template-es2015-compiler: 1.9.1
vuex: ^3.0.1 => 3.1.2
npmGlobalPackages:
@vue/cli: 4.1.2
联系方式
[QQ] 445305451
d***@qq.com
能不能自定义任意环境变量呀,VUE可以设置根目录下的.env文件来自定义,
如这个https://cli.vuejs.org/zh/guide/mode-and-env.html#%E6%A8%A1%E5%BC%8F
2020-03-26 11:54