Skip to content

Taro v3.3.19 build H5 设置env development编译报错 #12075

Answered by hqwlkj
WilsonLau0755 asked this question in Q & A
Discussion options

You must be logged in to vote

可以使用自定义环境变量来实现多环境的构建:

例如: 安装cross-env依赖

然后创建自己 CI/CD 的需要的环境,例如: staging, 然后在 config下创建 staging.js 文件

// eslint-disable-next-line import/no-commonjs
module.exports = {
  env: {
    NODE_ENV: '"staging"', // 这里是你的环境变量
  },
  defineConstants: {
  },
  mini: {},
  h5: {
  }
}

再在 config/index.js 的 module.exports 中新增

  if (process.env.NODE_ENV === 'staging') { // staging 是你配置的 环境变量名称
    return merge({}, config, require('./staging'))
  }

然后在 package.jsonscripts 新增 "staging:h5": "cross-env NODE_ENV=staging yarn build:h5",

修改你的 CI/CD 的大包命令为 :npm run staging:h5 就好啦

Replies: 4 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
5 replies
@cnqi2023
Comment options

@shuichangdonga
Comment options

@hqwlkj
Comment options

@shuichangdonga
Comment options

@holycrypto
Comment options

Answer selected by ZakaryCode
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q & A
Labels
V-3 Version - 3.x F-vue3 Framework - Vue 3 T-h5 Target - 编译到 H5
7 participants
Converted from issue

This discussion was converted from issue #11945 on July 19, 2022 12:47.