Skip to content

多环境与配置分层

本章你会学到什么

  • 如何组织 .env* 与运行时配置
  • 如何避免“开发环境 OK、线上坏掉”

推荐做法

  • 区分“构建期变量”和“运行时变量”:
    • 构建期:.env, .env.development, .env.production
    • 运行时:小程序 app.json/page.json 与远端配置(拉取后缓存)
  • 不提交敏感信息:AppID/密钥/token 放到 .env.local 或 CI 环境变量

常见坑

  • wx.getStorageSync 等运行时 API 写到构建期宏里(宏在 Node 执行)
  • 用环境变量拼接页面路径(会导致路由/分享 path 不稳定)

相关链接

  • 配置总览:/config/
  • 基础目录与资源收集:/config/paths
  • 构建输出与兼容:/config/build-and-output
  • JS 配置:/config/js
  • JSON 配置:/config/json
  • 共享配置(Wevu 默认值 / injectWeapi / HMR):/config/shared

Released under the MIT License.