Skip to content
This repository has been archived by the owner on Nov 17, 2022. It is now read-only.

[RFC] 原生小程序工程配置如何配置? #557

Closed
ChrisCindy opened this issue Sep 23, 2022 · 1 comment · May be fixed by #560
Closed

[RFC] 原生小程序工程配置如何配置? #557

ChrisCindy opened this issue Sep 23, 2022 · 1 comment · May be fixed by #560

Comments

@ChrisCindy
Copy link
Contributor

ChrisCindy commented Sep 23, 2022

Rax 的做法

build.json 中通过 miniapp.nativeConfig 字段配置:

// build.json 
{
  "targets": ["miniapp"],
  "miniapp": {
    "nativeConfig": {
      "appId": "YOUR_APP_ID"
    }
  }
}

编译过程中读取该字段并输出至 dist 目录的 project.config.json

Taro 的做法

在项目根目录或 src 目录放置 project.config.json,编译时将该文件拷贝至 dist 目录

ICE 怎么做?

个人倾向于 在 build.config.mts 中新增 miniapp 字段,在其中可配置小程序端的 nativeConfig

import { defineConfig } from '@ice/app';

export default defineConfig({
  miniapp: {
    nativeConfig: {
      appId: "YOUR_APP_ID"
    }
  }
});

当多端小程序存在差异时,使用环境变量(如 process.env.PLATFORM)进行差异化逻辑编写

@ChrisCindy ChrisCindy linked a pull request Sep 23, 2022 that will close this issue
@ChrisCindy
Copy link
Contributor Author

结论:用插件形式抽离小程序配置,小程序相关的配置放在插件配置中

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants