{"id":13487256,"url":"https://github.com/NewFuture/miniprogram-build","last_synced_at":"2025-03-27T21:32:14.430Z","repository":{"id":57297991,"uuid":"166657098","full_name":"NewFuture/miniprogram-build","owner":"NewFuture","description":"A command line tool to build wechat MiniProgram. 微信小程序命令行构建工具","archived":true,"fork":false,"pushed_at":"2022-09-07T07:31:50.000Z","size":861,"stargazers_count":59,"open_issues_count":2,"forks_count":13,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-17T17:17:59.918Z","etag":null,"topics":["cli","mini-programs","miniprogram","npm","scss","typescript","wechat"],"latest_commit_sha":null,"homepage":"https://miniprogram-build.newfuture.cc","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NewFuture.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-20T12:12:15.000Z","updated_at":"2024-11-30T05:55:41.000Z","dependencies_parsed_at":"2022-09-06T04:20:15.428Z","dependency_job_id":null,"html_url":"https://github.com/NewFuture/miniprogram-build","commit_stats":null,"previous_names":[],"tags_count":47,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NewFuture%2Fminiprogram-build","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NewFuture%2Fminiprogram-build/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NewFuture%2Fminiprogram-build/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NewFuture%2Fminiprogram-build/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NewFuture","download_url":"https://codeload.github.com/NewFuture/miniprogram-build/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245927387,"owners_count":20695227,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","mini-programs","miniprogram","npm","scss","typescript","wechat"],"created_at":"2024-07-31T18:00:57.093Z","updated_at":"2025-03-27T21:32:13.786Z","avatar_url":"https://github.com/NewFuture.png","language":"JavaScript","funding_links":[],"categories":["工具"],"sub_categories":[],"readme":"# [miniprogram-build](https://github.com/NewFuture/miniprogram-build)\n\n[![npm version](https://badge.fury.io/js/miniprogram-build.svg)](https://www.npmjs.com/package/miniprogram-build)\n[![cnpm version](https://npm.taobao.org/badge/v/miniprogram-build.svg)](https://npm.taobao.org/package/miniprogram-build)\n\n![Build Status](https://github.com/NewFuture/miniprogram-build/workflows/Node%20CI/badge.svg)\n[![Build Status](https://travis-ci.com/NewFuture/miniprogram-build.svg?branch=master)](https://travis-ci.com/NewFuture/miniprogram-build)\n[![Greenkeeper badge](https://badges.greenkeeper.io/NewFuture/miniprogram-build.svg)](https://greenkeeper.io/)\n\n\u003e A command line tool to build \u0026 watch MiniProgram. Not a Framework, just a tool.\n\u003e\n\u003e 小程序命令行构建工具。 不是开发框架,只是自动化的增强工具和开发流程。\n\n[template project 模板项目](https://github.com/NewFuture/miniprogram-template)\n\n![task flow](https://user-images.githubusercontent.com/6290356/56422894-43b87500-62dc-11e9-816c-24992b90f691.png)\n\n\u003e 注: **自动预览功能需要安装[微信开发工具](https://developers.weixin.qq.com/miniprogram/dev/devtools/download.html)并打开`端口设置`**\n\n## 使用 Usage\n\n### 立即尝试 quick start\n\n查看全部命令 show all commands (需要 npm \u003e= 5.2)\n\n```\nnpx miniprogram-build -h\n```\n\n### 作为开发依赖项 install as devDependence\n\n```\nnpm i miniprogram-build -D\n```\n\n### 命令参数 CLI\n\n\u003e `miniprogram-build [command...] [--option]`\n\nShort Alias [短名称]: `mp` 或 `mp-build`\n\n#### 命令 Commands:\n\n```\ndev         build and watch \u003c构建和检测文件修改\u003e\ninit        create config file \u003c创建配置文件\u003e\nbuild       clean and compile \u003c清理和编译所有文件\u003e\nwatch       watch file changes \u003c监测文件变化\u003e\ncompile     compile all source files to dist \u003c编译所有源文件\u003e\nclean       remove all files in dist \u003c清理dist\u003e\n\nupload      upload current project \u003c上传项目\u003e\nopen        open project in devtool \u003c打开项目\u003e\nautopreview auto-preview project \u003c当前项目发布自动预览\u003e\nclose       close dist in Wechat devtool \u003c开发工具中关闭项目\u003e\nquit        quit Wechat devtool \u003c退出微信开发工具\u003e\n\njs          compile ts/js files to `.js` \u003c编译生成js\u003e\nwxs         compile wxts/wxs files to `.wxs` \u003c编译生成wxs\u003e\nwxss        compile scss/sass/css/wxss to `.wxss` \u003c编译生成wxss\u003e\nwxml        compile html/wxml files to `.wxml` \u003c编译生成wxml\u003e\njson        compile all json/jsonc files to `.json` \u003c编译生成json\u003e\nimage       compresse all images in source to dist \u003c压缩所有图片\u003e\ncopy        copy all files match `copy` to dist \u003c复制需要复制的文件\u003e\nnpm         build npm dependencies to dist \u003c编译npm依赖\u003e\n```\n\n#### 参数 Options:\n\n```\n  --version     show version number \u003c查看本版号\u003e                       [boolean]\n  --production  production mode \u003c发布模式会优化压缩\u003e  [boolean] [default: false]\n  --src         source folder \u003c源文件目录\u003e           [string] [default: \"src\"]\n  --dist        output folder \u003c编译输出目录\u003e        [string] [default: \"dist\"]\n  --exclude     ignored files \u003c编译忽略文件(夹)\u003e                         [array]\n  --tsconfig    typescript config file \u003cTS配置,未设置会自动查找tsconfig.json\u003e\n  --copy        files to copy \u003c复制的文件\u003e\n  --assets      assets folder under src/ for compling style, wont put to dist\n                \u003c样式所需资源文件;会监测文件修改,但不会编译或复制到输出目录\u003e\n                                                    [string] [default: \"assets\"]\n  --var         KEY value pair to replace in js/json \u003c替换JS和JSON中的变量\u003e\n  -c, --config  JSON config file \u003c配置置文件,命令参数优先级高于配置\u003e\n  -h, --help    show help \u003c显示帮助信息\u003e                               [boolean]\n```\n\n#### 例子 examples\n\n-   使用配置`config.dev.json`开发调试, dev with `config.dev.json`\n\n```bash\nnpx miniprogram-build --config=config.dev.json\n```\n\n-   使用`config.prod.json`生产环境开启优化重新编译,rebuild for production with `config.prod.json`\n\n\u003e 如果 `production` 参数未指定, 环境变量中 NODE_ENV 为 `production`或`prod`时同样置为 `true`\n\n```bash\nnpx miniprogram-build build --config=./config.prod.json --production\n```\n\n-   编译替换`{` `{`__APP_ID__`}` `}`为 1234567, compile the source and replace template var `{` `{`__APP_ID__`}` `}` with 123456\n\n```bash\nnpx miniprogram-build compile --var.APP_ID=1234567\n```\n\n### 默认配置文件 default config\n\n```json\n{\n    \"production\": false,\n    \"src\": \"src\",\n    \"dist\": \"dist\",\n    \"assets\": \"assets\",\n    \"copy\": \"\",\n    \"exclude\": [],\n    \"tsconfig\": \"tsconfig.json\",\n    \"var\": {\n        \"APP_ID\": \"all {{APP_ID}} in json/ts files will replaced by this value\"\n    }\n}\n```\n\n可使用`init`命令生成配置文件\n\n```bash\nnpx miniprogram-build init\n```\n\n### 完整命令和参数 commands \u0026 options\n\n![commands \u0026 options](https://user-images.githubusercontent.com/6290356/53295185-f4504e00-3830-11e9-8bb0-31a533c8da7c.png)\n\n### tips\n\n-   CSS npm packags install as devDependences with `npm i -D` (CSS 的 npm 依赖使用`npm i -D`方式安装)\n\n## Features\n\n-   `js`\n    -   [x] compile `TS`\n    -   [x] sourcemaps\n    -   [x] replace `{` `{`__VAR_NAME__`}` `}`\n    -   [x] tree shaking\n-   `wxs`\n    -   [x] compile `TS` (`.wxts`)\n    -   [x] replace `{` `{`__VAR_NAME__`}` `}`\n    -   [x] npm support\n    -   [x] tree shaking\n-   `wxss`\n    -   [x] compile\n        -   `scss`/`sass`\n        -   `css`\n    -   [x] replace `{` `{`__VAR_NAME__`}` `}` (注意: 为了防止 stylelint 报错, 需要将变量用引号包裹起来, 内部会自动去除)\n    -   [x] import `node_modules`\n    -   [x] sourcemaps\n    -   [x] minify (release) / expanded (debug)\n    -   [x] inline image\n        -   svg datauri\n        -   png/jpg base64\n        -   image compress\n    -   [x] clean-css\n    -   [x] keep import wxss\n    -   [x] assest folder\n-   `wxml`\n    -   [x] `wxml`\n    -   [x] `html`\n    -   [x] copy rename\n    -   [x] error report\n-   `JSON`\n    -   [x] comments (添加注释)\n    -   [x] trailing comma\n    -   [x] minify\n    -   [x] replace `{` `{`__VAR_NAME__`}` `}`\n-   miniprogram npm\n    -   [x] rollup js lib\n    -   [x] components\n-   resource\n    -   [x] copy/src\n    -   [x] image compress\n    -   [x] error report\n-   console verbose\n    -   [x] all files\n    -   [x] file size\n\n## Todo\n\n-   [x] exclude path\n-   [x] multi watcher\n-   [x] config\n-   [x] 显示报错位置\n-   [x] break errors\n-   [ ] cache\n\n## test examples\n\nsee [test](test/)\n\n```\nnpm i\nnpm start\n\n[21:31:41] config: v0.0.0 load config .mpconfig.jsonc\n[21:31:41] 0.clean: dist\n[21:31:41] ↓↓↓↓↓↓ start compile: src → dist ↓↓↓↓↓↓\n[21:31:42] 3.wxss: [►] app.scss → app.wxss\n[21:31:42] 4.json: [►] app.jsonc → app.json\n[21:31:42] replace: √ {{APP_ID}} → 123456 (app.json)\n[21:31:42] 5.typescript: [►] app.ts → app.js\n[21:31:42] replace: √ {{APP_ID}} → 123456 (app.ts)\n[21:31:42] inline: assets\\images\\arrow-up.svg → (app.css)\n[21:31:42] 6.image: icons\\uEA01-arrow-down.svg  (saved 586 B - 76.8%)\n[21:31:42] 2.npm: [►] \u003cminiprogram-image(component)\u003e → miniprogram_npm\\miniprogram-image\\index.js\n[21:31:42] 2.npm: [►] \u003cminiprogram-network\u003e → miniprogram_npm\\miniprogram-network\\index.js\n[21:31:42] 1.wxts: [►] wxs\\comm.wxts → wxs\\comm.wxs\n[21:31:42] 7.javascript: [►] lib\\t.js → lib\\t.js\n[21:31:42] replace: √ {{APP_ID}} → 123456 (lib\\t.js)\n[21:31:42] 3.wxss: [►] pages\\index\\index.scss → pages\\index\\index.wxss\n[21:31:42] 5.typescript: [►] lib\\test.ts → lib\\test.js\n[21:31:42] 2.npm: [►] \u003cminiprogram-image(component)\u003e → miniprogram_npm\\miniprogram-image\\index.json\n[21:31:42] 1.wxts: [►] wxs\\x.wxts → wxs\\x.wxs\n[21:31:42] 4.json: [√] app.json (40 B)\n[21:31:42] 6.image: √ All 1 file done! (177 B)[1.06秒]\n[21:31:42] 5.typescript: [►] pages\\index\\index.ts → pages\\index\\index.js\n[21:31:44] 7.javascript: [√] lib\\t.js (286 B)\n[21:31:44] 2.npm: [►] \u003cminiprogram-image(component)\u003e → miniprogram_npm\\miniprogram-image\\index.wxml\n[21:31:44] 3.wxss: [√] app.wxss (1.02 kB)\n[21:31:44] 8.wxml: [√] pages\\index\\index.wxml (360 B)\n[21:31:44] 2.npm: [►] \u003cminiprogram-image(component)\u003e → miniprogram_npm\\miniprogram-image\\index.wxss\n[21:31:44] 3.wxss: [√] pages\\index\\index.wxss (562 B)\n[21:31:44] 3.wxss: √ All 2 files done! (1.59 kB)[2.44秒]\n[21:31:44] 5.typescript: [√] app.js.map (431 B)\n[21:31:44] 5.typescript: [√] app.js (269 B)\n[21:31:44] 2.npm: √\u003cminiprogram-image(component)\u003e All 4 files done! (6.99 kB)[2.05秒]\n[21:31:44] 5.typescript: [√] lib\\test.js.map (162 B)\n[21:31:44] 5.typescript: [√] lib\\test.js (130 B)\n[21:31:44] 5.typescript: [√] pages\\index\\index.js.map (235 B)\n[21:31:44] 5.typescript: [√] pages\\index\\index.js (178 B)\n[21:31:44] 5.typescript: √ All 6 files done! (1.41 kB)[2.19秒]\n[21:31:44] replace: √ {{APP_ID}} → 123456 (wxs\\comm.wxs)\n[21:31:44] 1.wxts: [√] wxs\\comm.wxs (16.2 kB)\n[21:31:44] 2.npm: √\u003cminiprogram-network\u003e All 1 file done! (28.3 kB)[2.48秒]\n[21:31:44] 1.wxts: [√] wxs\\x.wxs (66 B)\n[21:31:44] 1.wxts: √ All 2 files done! (16.3 kB)[2.52秒]\n[21:31:44] ↑↑↑↑↑↑ √ All compilation tasks done! ↑↑↑↑↑↑\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNewFuture%2Fminiprogram-build","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FNewFuture%2Fminiprogram-build","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNewFuture%2Fminiprogram-build/lists"}