Taro: config 文件中 BASE_URL 的获取 ?

Created on 28 May 2020  ·  2Comments  ·  Source: NervJS/taro

问题描述


在 taro 的 config 文件中 设置 BASE_URL 代码 如下

module.exports = {
  env: {
    NODE_ENV: '"development"'
  },
  BASE_URL: '"https://test-mpcs.fleetingpower.com"',
  defineConstants: {},
  weapp: {},
  h5: {}
};


但是打印的时候 console.log(process.BASE_URL) 永远是 undefined
不知道怎么使用

复现步骤

/**
 * 这段注释后可以贴代码
 * 提供完整可复现的代码和整理好代码格式,有助于我们快速定位问题,节省你我时间
 * 代码提供不全或代码格式混乱的 issues 【有可能会被忽略】
 * 
 * 查看如何插入代码:https://coding.net/help/doc/project/markdown.html#i-5
 */


期望行为

报错信息

系统信息

Taro CLI 2.0.6 environment info:
System:
OS: macOS High Sierra 10.13.6
Shell: 5.3 - /bin/zsh
Binaries:
Node: 10.16.2 - /usr/local/bin/node
Yarn: 1.21.1 - /usr/local/bin/yarn
npm: 6.11.2 - /usr/local/bin/npm
npmPackages:
@tarojs/async-await: 2.0.6 => 2.0.6
@tarojs/components: 2.0.6 => 2.0.6
@tarojs/mini-runner: 2.0.6 => 2.0.6
@tarojs/plugin-babel: 2.0.6 => 2.0.6
@tarojs/plugin-csso: 2.0.6 => 2.0.6
@tarojs/plugin-less: 2.0.6 => 2.0.6
@tarojs/plugin-sass: 2.0.6 => 2.0.6
@tarojs/plugin-uglifyjs: 2.0.6 => 2.0.6
@tarojs/redux: 2.0.6 => 2.0.6
@tarojs/redux-h5: 2.0.6 => 2.0.6
@tarojs/router: 2.0.6 => 2.0.6
@tarojs/taro: 2.0.6 => 2.0.6
@tarojs/taro-alipay: 2.0.6 => 2.0.6
@tarojs/taro-h5: 2.0.6 => 2.0.6
@tarojs/taro-swan: 2.0.6 => 2.0.6
@tarojs/taro-tt: 2.0.6 => 2.0.6
@tarojs/taro-weapp: 2.0.6 => 2.0.6
@tarojs/webpack-runner: 2.0.6 => 2.0.6
eslint-config-taro: 2.0.6 => 2.0.6
eslint-plugin-taro: 2.0.6 => 2.0.6
nerv-devtools: ^1.5.6 => 1.5.6
nervjs: ^1.5.6 => 1.5.6
stylelint-config-taro-rn: 2.0.6 => 2.0.6
stylelint-taro-rn: 2.0.6 => 2.0.6

补充信息

如果您有功能上的建议,可以提到 FeatHub

使用上的问题,欢迎在「Taro 社区」一起交流

question

Most helpful comment

看 docs 仔细一些, 正确写法:

module.exports = {
  ...,
  defineConstants: {
    BASE_URL: '"https://test-mpcs.fleetingpower.com"',
  },
};

All 2 comments

看 docs 仔细一些, 正确写法:

module.exports = {
  ...,
  defineConstants: {
    BASE_URL: '"https://test-mpcs.fleetingpower.com"',
  },
};

感谢

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chankamlam picture chankamlam  ·  3Comments

deepcoldy picture deepcoldy  ·  3Comments

leafchao picture leafchao  ·  3Comments

fxy5869571 picture fxy5869571  ·  3Comments

zhuxianguo picture zhuxianguo  ·  3Comments