# 项目配置

# tms.config.js

在项目根目录下创建tms.config.js, 该配置是构建工具对于不同小程序项目抽取的配置能力,不同项目可以根据自己的需求定制相关功能;

const path = require("path");
module.exports = () => ({
  // 小程序项目名称
  appName: "demo",
  // 小程序的appId
  appId: "wx65cc950f42e8fff1",
  // 小程序主包包含的分包(对应subPckages描述的name字段)
  mainPackages: ["index"],
  modules: { // 描述小程序模块的配置
    all: [  // 项目包含哪些模块
      {
        // 模块名称
        moduleName: "index", // 与module.config.json的moduleName字段对应
        // 模块源码路径(模块源码根目录必须包含module.config.json);支持相对路径(相对tms.config.js的路径),
        path: "./modules/index",
      },
      {
        // 模块名称
        moduleName: "home",
        // 模块支持集成第三方git仓库代码
        repoInfo: {
          httpRepoUrl: "https://git.woa.com/**.git",
          buildGitTag: "master", // 拉取远程仓库的分支
          path: 'package' // 模块源码在远程仓库的某个路径下,可以配置此字段,默认为空
        },
        // 模块源码路径,第三方代码下载路径
        path: "./modules/home/ccmhome",
      },
    ],
    include: ['index'] // 上面all声明的模块,多模块开发时,本地启动哪个模块, 填写moduleName模块名
    exclude: ['home'] // 上面all声明的模块,多模块开发时,本地启排除哪些模块,填写moduleName模块名
    blockRemote: false // 使用屏蔽远程模块, 默认false
  }
  
  //项目包含哪些云函数 
  cloudModules: {
    all: [{
      name: 'analysis', // 云函数的名称
	    path: '../../cloud/analysis' // 云函数的源码路径
    }],
    include: ['analysis'] // 上面all声明的云函数,多模块开发时,本地启动哪个云函数, 填写name云函数名字
  },
  cloudDir: 'cloud', // 云函数的编译目录,默认是当前小程序项目的cloud目录
  // 静态资源目录,从源码路径拷贝到输出路径
  static: [
    {
      from: `./config/**/*`, // glob匹配源码路径
      to: `./dist//config/`, // 输出路径
    },
  ],
  // git仓库账号,下载第三方模块git仓库时,优先读取配置的账号信息下载仓库
  gitAccout: {
    // 仓库地址,上面modules>all字段注册的第三方仓库的仓库地址
    "https://git.woa.com/**.git": {
      // git用户名
      username: "zhangsan",
      // git 密码
      pass: "***",
    },
    
  },
  // 安装npm时,支持配置npm源,同时支持按scope配置npm源
  npm: {
    registry: 'https://registry.npmjs.org/',
    scope: {
      '@tencent': 'http://mirrors.tencent.com/npm/',
    },
  },
  /** 预览二维码的配置 https://developers.weixin.qq.com/miniprogram/dev/devtools/ci.html#%E9%A2%84%E8%A7%88  */
  // tmskit run preview命令除了支持--qrcodeFormat等重点命令参数外, 也支持更详细的配置信息,详见上面链接。命令参数的优先级<tms.config.js的配置
  preview: {
    robot: 2, // 指定使用哪一个 ci 机器人,可选值:1 ~ 30
    desc: '',  // 自定义备注,将显示在“小程序助手”开发版列表中
    infoInput: './preview.json' //'相关信息会被输出到给定路径文件
    ...
  },
  /** 上传的配置  https://developers.weixin.qq.com/miniprogram/dev/devtools/ci.html#%E7%BC%96%E8%AF%91%E8%AE%BE%E7%BD%AE */
   // tmskit run upload命令除了支持--version等重点命令参数外, 也支持更详细的配置信息,详见上面链接。 命令参数的优先级<tms.config.js的配置
  upload: {
    robot: 2, // 指定使用哪一个 ci 机器人,可选值:1 ~ 30
    version: '2022.08.03', // 版本号
    desc: '', // 自定义备注,将显示在“小程序助手”开发版列表中
    infoInput: './upload.json' //'相关信息会被输出到给定路径文件
    ...
  },
  // 对外暴露的编译插件 - 详见/tmskit/extend/plugins.html
  plugins: []
  // 对外暴露的钩子 - 详见/tmskit/extend/hooks.html
  hooks: {},
  // 扩展命令 - 详见/tmskit/extend/commands.html
  commands: []
});

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
  • modules参数详解
字段 字段类型 配置说明 示例
modules Object
{
  "all": [] // 用来声明项目包含的所有模块(格式见上)
  include": ["home"],// 多模块开发时,启动哪个模块
  "exclude": ["home"],// 多模块开发时,排除哪个模块
  "blockRemote": true // 屏蔽远程模块
}
include、exclude、blockRemote都是从all声明的模块中检索模块
优先级include>exclude>blockRemote, 即:
如果声明了include, 则会忽略exclude和blockRemote的设置。未指定则跑全量模块。直接传入数组按 include 规则处理。
["home", "aggretakecar"]

{
  "blockRemote": true
}

ps: 修改此文件需要重新执行tmskit run dev;

# tms.private.config.js

此文件是开发者私人配置文件,字段与tms.config.js一致,是对tms.config.js文件的覆盖补充,优先级tms.private.config.js > tms.config.js.
此文件可以添加到.gitingre中,不需要提交到 git 仓库,仅本地开发使用,存放于项目的根目录下。

  1. 每个开发者本地开发的模块不一样,可以在modules字段中,声明个人启动的模块
  2. 小程序支持集成支持第三方 git 仓库的模块,但是当开发者没有第三方代码仓库下载权限时,可以让第三方仓库的管理员提供相关下载仓库代码的账号。
    git账号信息是私密信息推荐放到tms.private.config.js中无需提交到git仓库中,既保证了安全又能下载第三方仓库的模块。
module.exports = {

  modules: { // 启动的模块
    // 优先级include>exclude>blockRemote, 即:如果声明了include, 则会忽略exclude和blockRemote的设置。未指定include则跑全量模块.
    include: [ 'car']       //包含哪些模块, 填写模块磨成
    exclude: ['aggrecarshop'] // 排除哪些模块
    blockRemote: true, // 屏蔽第三方仓库的代码
  },
  // git仓库账号
  gitAccout: {
    // 模块名
    route: {
      // git用户名
      username: "zhangsan",
      // git 密码
      pass: "***",
    },
  },
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

ps: 修改此文件需要重新执行 tmskit run dev

Last Updated: 8/15/2022, 19:19:13