Skip to content

project.config.json

project.config.json 是小程序项目配置文件,用于保存项目的一些配置信息和开发者的个人设置。

提示

project.config.private.json 会覆盖 project.config.json 中的配置项,优先级更高。

compileType

compileType 是一个字符串,用于指定小程序的编译类型。当前支持的编译类型有 miniprogramplugin,分别对应小程序和插件项目。

json
{
  "compileType": "miniprogram"
}

projectname

projectname 是一个字符串,用于指定小程序的名称。这个名称会显示在微信开发者工具中,方便开发者识别和管理多个小程序项目。

json
{
  "projectname": "my-mini-program"
}

appid

appid 是小程序的唯一标识,开发者需要在微信公众平台上注册小程序并获取 appid,然后将其配置在 project.config.json 中。

json
{
  "appid": "wx1234567890abcdef"
}

miniprogramRoot

miniprogramRoot 是一个字符串,用于指定小程序的根目录。

json
{
  "miniprogramRoot": "miniprogram/"
}

srcMiniprogramRoot

srcMiniprogramRoot 是一个字符串,用于指定小程序源代码的根目录。

json
{
  "srcMiniprogramRoot": "miniprogram/"
}

cloudfunctionRoot

cloudfunctionRoot 是一个字符串,用于指定云函数的根目录。

json
{
  "cloudfunctionRoot": "cloudfunctions/"
}

libVersion

libVersion 是一个字符串,用于指定小程序使用的基础库版本。开发者可以根据需要选择不同的基础库版本,以获得不同的功能和性能优化。

json
{
  "libVersion": "2.30.0"
}

setting

本地设置

json
/* prettier-ignore */
{
  "condition": false,                   // 启动条件编译 (默认值: false)
  "es6": true,                          // 将 JS 编译成 ES5 (默认值: true)
  "swc": false,                         // 使用 SWC 编译脚本文件 (默认值: false)
  "compileWorklet": false,              // 编译 worklet 代码 (默认值: false)
  "postcss": true,                      // 上传代码时样式自动补全 (默认值: true)
  "minifyWXSS": true,                   // 上传代码时自动压缩样式文件 (默认值: true)
  "minified": true,                      // 上传代码时自动压缩脚本文件 (默认值: true)
  "minifyWXML": true,                   // 上传代码时自动压缩 wxml 文件 (默认值: true)
  "ignoreUploadUnusedFiles": true,      // 上传时过滤无依赖文件 (默认值: true)
  "uglifyFileName": false,              // 上传时进行代码保护 (默认值: false)
  "autoAudits": false,                  // 自动运行体验评分 (默认值: false)
  "urlCheck": false,                    // 不校验合法域名、web-view(业务域名)、TLS 版本以及 HTTPS 证书 (默认值: true)
  "bigPackageSizeSupport": false,       // 预览及真机调试时主包、分包体积上限调整为4M (默认值: false)
  "compileHotReLoad": false,            // 启用代码自动热重载 (默认值: false)
  "skylineRenderEnable": false,         // 开启 Skyline 渲染调试 (默认值: false)
  "enhance": true,                      // 启用多核心编译 (默认值: true)
  
  // 启用自定义处理命令
  "scripts": {
    "beforeCompile": "aaa",
    "beforePreview": "bbb",
    "beforeUpload": "ccc"
  }
}

useCompilerPlugins

useCompilerPlugins 是一个数组,用于指定需要使用的编译插件。目前支持编译插件有 typescriptlesssass

json
{
  "useCompilerPlugins": ["typescript", "sass"]
}

ignoreDevUnusedFiles

ignoreDevUnusedFiles 是一个布尔值,用于指定在开发环境下是否忽略未使用的文件。如果设置为 true,则在开发环境下会忽略未使用的文件,从而提高开发效率。

json
{
  "ignoreDevUnusedFiles": true
}

condition

condition 是一个对象,用于指定小程序的条件编译配置。开发者可以根据不同的条件编译不同的代码,以适应不同的运行环境。

json
{
  "condition": {
    "miniprogram": {
      "list": [
        {
          "name": "微信接口功能演示",
          "pathName": "pages/index/index",
          "query": "a=1&b=2",
          "launchMode": "default"
        }
      ]
    }
  }
}

常见问题

message: NPM packages not found. Please confirm npm packages which need to build are belong to `miniprogramRoot` directory. Or you may edit project.config.json's `packNpmManually` and `packNpmRelationList`

  1. 项目依赖 xxx 在根目录的 package.json 中,但微信小程序需要在 miniprogram/ 目录下也有 package.json 才能正确构建 npm。

    json
    {
      "packNpmManually": true,
      "packNpmRelationList": [
        {
          "packageJsonPath": "./package.json",
          "miniprogramNpmDistDir": "./miniprogram/"
        },
        {
          "packageJsonPath": "./miniprogram/package.json",
          "miniprogramNpmDistDir": "./miniprogram/"
        }
      ]
    }
  2. 推荐云开发和小程序开发使用不同的 package.json 来分别管理。

基于 MIT 许可发布