NervJS / taro

开放式跨端跨框架解决方案,支持使用 React/Vue/Nerv 等框架来开发微信/京东/百度/支付宝/字节跳动/ QQ 小程序/H5/React Native 等应用。 https://taro.zone/
https://docs.taro.zone/
Other
35.26k stars 4.76k forks source link

根据环境变量替换 appid #8492

Closed Lyokoo closed 1 year ago

Lyokoo commented 3 years ago

请教一下,我们有多个宿主端运行小程序的需求,希望能够根据 Node 环境变量替换不同的 appid,我尝试了 webpack-plugin-replace 没有效果

编译配置

{
    env: {
      APP_NAME: JSON.stringify('xigua'),
    },
    mini: {
      webpackChain (chain) {
        chain.merge({
          plugin: {
            replacePlugin: {
              plugin: require('webpack-plugin-replace'),
              args: [{
                __APP_ID__: 'xxxx',
              }]
            }
          }
        })
      }
    }
  }

project.tt.json

{
  "miniprogramRoot": "./dist",
  "projectname": "xxxxxx",
  "description": "xxxxxx",
  "appid": "__APP_ID__",
  "setting": {
    "urlCheck": true,
    "es6": false,
    "postcss": false,
    "minified": false
  },
  "compileType": "miniprogram"
}
ZakaryCode commented 1 year ago

https://nervjs.github.io/taro-docs/docs/env-mode-config/