cocos_register_post_build_patch
Register patches to automatically modify build files after each successful Cocos Creator build, preserving customizations that would otherwise be overwritten.
Instructions
Register declarative patches that auto-apply after every successful build.
Use when a customization has no Cocos source-config switch and
would otherwise get wiped on the next cocos_build (classic
examples: style.css body background, project.config.json
fields WeChat wants beyond what builder.json exposes, custom
index.html overrides).
Each patch dict needs:
platform: str — "web-mobile" / "wechatgame" / "ios" / etc.
file: str — path relative to build/<platform>/ (no
absolute paths, no '..' segments).
kind: one of:
- "json_set" + path (dotted key) + value
- "regex_sub" + find (regex) + replace (str)
- "copy_from" + source (project-relative path to src file)
mode: "append" (default) adds to existing list, "replace"
overwrites. To clear all patches, pass patches=[] with "replace".
All patches are validated at register time — invalid regex or unsafe path fails here, not at build time.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_path | Yes | ||
| patches | Yes | ||
| mode | No | append |