jimmy163
jimmy163
  • 发布:2020-03-02 16:46
  • 更新:2022-06-08 13:39
  • 阅读:2026

【报Bug】package.json扩展配置用法, 环境变量配置不生效

分类:uni-app

详细问题描述

(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

2020-03-02 16:46 负责人:无 分享
已邀请:
DCloud_uniCloud_WYQ

DCloud_uniCloud_WYQ

package.json扩展配置目前仅为了实现自定义条件编译平台,不支持任意设置环境变量

  • 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

d***@qq.com

d***@qq.com

能不能自定义任意环境变量呀,VUE可以设置根目录下的.env文件来自定义,
如这个https://cli.vuejs.org/zh/guide/mode-and-env.html#%E6%A8%A1%E5%BC%8F

  • DCloud_uniCloud_WYQ

    可以创建uni-app的cli项目 https://uniapp.dcloud.io/quickstart?id=_2-%e9%80%9a%e8%bf%87vue-cli%e5%91%bd%e4%bb%a4%e8%a1%8c

    2020-03-26 12:11

  • 270315475

    回复 DCloud_uniCloud_WYQ: 可以通过cli 拉起小程序吗

    2020-10-27 13:19

d***@cdgwin.com

d***@cdgwin.com

那文档中写的其他环境变量岂不是搞笑呢?还有自定义条件编译,都是搞笑呢?

该问题目前已经被锁定, 无法添加新回复