{"id":13487197,"url":"https://github.com/Jeff2Ma/WeApp-Workflow","last_synced_at":"2025-03-27T21:32:03.812Z","repository":{"id":45522434,"uuid":"97863290","full_name":"Jeff2Ma/WeApp-Workflow","owner":"Jeff2Ma","description":"基于Gulp 的微信小程序前端开发工作流 💯","archived":false,"fork":false,"pushed_at":"2020-04-26T13:44:11.000Z","size":3132,"stargazers_count":254,"open_issues_count":12,"forks_count":62,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-03-15T19:16:39.405Z","etag":null,"topics":["csssprite","front-end","gulp","scss","weapp","wechat","weixin","workflow"],"latest_commit_sha":null,"homepage":"","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/Jeff2Ma.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2017-07-20T17:50:29.000Z","updated_at":"2025-03-07T10:22:54.000Z","dependencies_parsed_at":"2022-07-16T01:30:30.558Z","dependency_job_id":null,"html_url":"https://github.com/Jeff2Ma/WeApp-Workflow","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jeff2Ma%2FWeApp-Workflow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jeff2Ma%2FWeApp-Workflow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jeff2Ma%2FWeApp-Workflow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jeff2Ma%2FWeApp-Workflow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Jeff2Ma","download_url":"https://codeload.github.com/Jeff2Ma/WeApp-Workflow/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245294769,"owners_count":20591900,"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":["csssprite","front-end","gulp","scss","weapp","wechat","weixin","workflow"],"created_at":"2024-07-31T18:00:56.482Z","updated_at":"2025-03-27T21:32:03.014Z","avatar_url":"https://github.com/Jeff2Ma.png","language":"JavaScript","funding_links":[],"categories":["工具"],"sub_categories":[],"readme":"![https://github.com/Jeff2Ma/WeApp-Workflow](src/assets/images/weapp-worfkflow-banner2@2x.jpg)\n\n\u003e [WeApp-Workflow](https://github.com/Jeff2Ma/WeApp-Workflow)：基于Gulp 的微信小程序前端开发工作流\n\n## 介绍\n\n[![Greenkeeper badge](https://badges.greenkeeper.io/Jeff2Ma/WeApp-Workflow.svg)](https://greenkeeper.io/)\n\nWeApp-Workflow 是一个专门为开发微信小程序打造的前端开发工作流，基于Gulp 4 开发，旨在通过工作流的方式解决微信小程序开发过程中写前端代码的痛点。\n\n项目主页：[https://github.com/Jeff2Ma/WeApp-Workflow](https://github.com/Jeff2Ma/WeApp-Workflow)\n\n文章介绍：[https://devework.com/weapp-workflow.html](https://devework.com/weapp-workflow.html)\n\n## 功能\n\n### SCSS 实时编译为 WXSS\n\n使用Sass 预处理器，让写CSS 更加顺畅。`.scss`文件会实时编译为微信小程序支持的`.wxss`文件。\n\n### WXSS(CSS) 中px 单位转小程序单位rpx\n\n以官方推荐的iPhone 6 为标准设计格式，开发中直接写`px` 即可自动转换为`rpx`。\n\n```css\n// Input: src/pages/index/index.scss\n.index__header {\n\tfont-size: 14px;\n\tmargin-top: 20PX; /* 如果为大写的`PX`单位则不会转换 */\n}\n\n// Output: dist/pages/index/index.wxss\n.index__header {\n\tfont-size: 28rpx;\n\tmargin-top: 20PX; /* 如果为大写的`PX`单位则不会转换 */\n}\n\n```\n\n### 图片压缩\n\n实时压缩图片并采用增量方式防止被重复压缩。\n\n### 自动上传图片到CDN 并更新路径为https 绝对路径\n\n小程序不支持相对路径的图片引用，仅支持带`https`协议头的绝对路径。本工作流可以将WXML 以及WXSS 文件中引用的相对路径图片上传到云存储CDN 或通过FTP/SFTP 协议上传到个人服务器空间。目前支持腾讯云，七牛云。\n\n```html\n// Input: src/pages/index/index.wxml\n\u003cimage src=\"%ASSETS_IMG%/t.png\"\u003e\u003c/image\u003e\n\n// Output: dist/pages/index/index.wxml\n\u003cimage src=\"https://cdn.devework.com/weapp/devework/t.png\"\u003e\u003c/image\u003e\n```\n\n### Font 文件转为base64 编码\n\n小程序不支持相对路径的字体文件，本工作流可将CSS 中引用到的Font 文件转码为base64 并替换原路径。\n\n```\n// Input: src/pages/index/index.scss\n@font-face {\n  font-family: 'fontello';\n  src: url(\"assets/fonts/fontello.ttf\") format('truetype');\n}\n\n// Output: dist/pages/index/index.wxss\n@font-face {\n  font-family: 'fontello';\n  src: url(data:application/font-sfnt;charset=utf-8;base64,AAEAAAAPAIAA....FsASNsQIARAAA) format(\"truetype\");\n}\n\n```\n### 全自动构建雪碧图及生成相应CSS\n\n本功能由[postcss-lazysprite](https://github.com/Jeff2Ma/postcss-lazysprite) 插件驱动。开发中准备好图片后仅仅写一句类似`@lazysprite \"xxxx\"`的代码，即可全自动构建雪碧图及生成相应CSS。\n\n```css\n// Input: src/app.scss\n@lazysprite \"filetype\";\n\n// Output: dist/app.wxss\n.icon-filetype-doc {\n    background-image: url(../sprites/filetype.png);\n    background-position: 0 0;\n    width: 80px;\n    height: 80px;\n}\n\n.icon-filetype-pdf {\n    background-image: url(../sprites/filetype.png);\n    background-position: -90px 0;\n    width: 80px;\n    height: 80px;\n}\n\n@media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min-device-pixel-ratio:2) {\n    .icon-filetype-doc {\n        background-image: url(../sprites/filetype@2x.png);\n        background-position: 0 0;\n        background-size: 170px 170px;\n    }\n\n    .icon-filetype-pdf {\n        background-image: url(../sprites/filetype@2x.png);\n        background-position: -90px 0;\n        background-size: 170px 170px;\n    }\n}\n```\n\n## 亮点\n\n### Gulp4\n\n采用最新的Gulp 4版本的新特征，让工作流运行更快。\n\n### 简洁不简单\n\n核心只有一个默认任务，通过合理的任务搭配机制减少繁琐流程及来回运行终端，让开发更便捷。\n\n### 增量更新机制，运行起来更快\n\n引入Sass 的增量编译以及图片相关任务的增量更新机制，让工作流运行速度更快。\n\n## 项目结构\n\n```\n.\n├── config.custom.js // gulp自定义配置，会覆盖config.js\n├── config.js // gulp 配置文件\n├── gulpfile.js\n├── package.json\n├── src // 开发目录\n│   ├── app.js\n│   ├── app.json\n│   ├── app.scss\n│   ├── assets // 开发相关的静态文件原始资源\n│   │   ├── fonts //字体文件\n│   │   ├── images // 图片文件，可被上传到CDN\n│   │   ├── scss // 一般放置SCSS 的minxins 等被import 的SCSS 文件\n│   │   └── sprites // 生成雪碧图小图的目录\n│   ├── image // 小程序专用的图片资源（如tabbar icon）目录\n│   ├── pages\n│   └── utils\n├── tmp //  通过src 目录编译后生成的缓存目录\n└── dist // 通过src 目录编译后生成的文件目录，也是小程序开发的项目目录\n\n```\n\n## 开始使用\n\n\u003e Node 版本建议在v4 以上。因为该工作流涉及到第三方依赖，建议在科学上网的环境下操作。\n\n### 安装\n\n0、请先全局按照 Gulp-cli\n\n```\nnpm install gulp-cli -g\n```\n\n1、通过`git clone`下载项目文件。\n\n```\ngit clone https://github.com/Jeff2Ma/WeApp-Workflow\n```\n2、建议删除`.git`目录（Windows 用户请手动删除）\n\n```\ncd WeApp-Workflow\nrm -rf .git\n```\n\n3、安装必要模块\n\n```\nnpm i\n```\n\n4、启动开发\n\n建议复制`config.js`并重命名为`config.custom.js`，然后根据个人实际需求改写相关配置信息（每个配置项均有注释说明）。接下来在终端中运行如下命令开启：\n\n```\ngulp\n```\n\n![iterm](src/assets/images/iterm.png)\n\n其余任务：`gulp clean`：清除`dist`，`tmp`文件夹。\n\n### 配置\n\n完成以上操作后，需要在“微信web 开发者工具”也进行相关设置（以 v1.x 为准，不再兼容 v0.x 版）。\n\n1、新建项目，直接选择整个项目目录，即`project.config.json` 所在的目录作为项目目录。\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"src/assets/images/s1.png\" alt=\"WeApp-Workflow配置\" style=\"max-width:600px;height: auto;\"\u003e\n\u003c/p\u003e\n\n### 开发\n\n接下来进入常规开发即可。开发过程中，**使用第三方编辑器（WebStorm、Sublime Text 等）编辑`src`目录下的文件**，保存修改后gulp 进程会实时编译到`dist`目录相应的位置。而**微信web 开发者工具会自动编译刷新，此时仅充当预览功能**。\n\n开发要点说明：\n\n- **SCSS 开发**：直接在`src/pages/page-name`下进行编辑`page-name.scss`，会自动转化为`page-name.wxss` 并放置到`dist`目录相应位置。开发过程中涉及到数值的地方直接写`px`单位（按iPhone6 为标准设计稿），会自动计算转化为`rpx`单位。如果特殊情况不想转化，请写大写的`PX`。\n\n- **WXML开发**：除**CDN 图片**功能需要特殊写图片路径外，其它无特殊要求。\n\n- **WebFont**：先在fontell.com 这类网站制作好雪碧图然后拿到ttf 格式的文件到`src/assets/fonts`下，常规方式引用即可自动base64 转码。\n\n- **CDN 图片**：（该功能默认关闭，需自行在设置项开启）微信小程序中wxss 或wxml 不支持相对路径的图片，需要https 开头的绝对路径。本工作流可以使得开发时候直接写相对路径，工作流会帮忙上传到CDN 并替换原路径。此类图片必须放置到`src/assets/images`下，然后在wxml 或CSS 中用`%ASSETS_IMG%/filename.png`的方式写路径。`%ASSETS_IMG%`为自定义的目录供后续字符串替换。\n\n- **雪碧图**：首先在小程序中不建议用雪碧图，直接用单图或者WebFont 的形式更好。如果一定要用，按照代码中的小程序示例放置**小图目录**到`src/assets/sprites`下然后在SCSS 中通过`@lazysprite \"xxxx\"`调用即可（建议调用代码放到`app.scss`下）。雪碧图高级用法请[点击这里](https://github.com/Jeff2Ma/postcss-lazysprite)。\n\n## Q\u0026A\n\n- Q：为什么工作流中没有AutoPrefixer 的功能？\n\n\tA：因为微信开发者工具的“项目”中“样式补全”选项已经提供了这个功能；\n\n- Q：为什么工作流中没有配置bable 的ES6 转ES5 的功能？\n\n\tA：如上，微信开发者工具已经提供。\n\n- Q：跟[WePY](https://github.com/wepyjs/wepy) 这类小程序开发框架相比优势在哪？\n\n\tA：微信支付团队开发的WePY 确实是一个不错的工具。如果跟WePY 放到同一水平线对比，WeApp-Workflow 根本没有优势。WeApp-Workflow 是一个workflow 工具，不是一个开发框架，其侧重的是小程序中CSS 层面的开发，对于一部分开发者来说，他/她的小程序并不需要WePY 那么重的开发框架。\n\n- Q：WeApp-Workflow 没有相应专门的编译任务（类似`gulp build`,`npm run build`这种）？\n\n\tA：是的，因为WeApp-Workflow 是适合用来开发“小”的小程序而非复杂的小程序，所以综合考虑开发速度、代码量等方面，没有专门的开发阶段一个任务(dev)，开发完成阶段额外一个编译任务(buid)。直接一个任务就行。\n\n## 案例展示\n\n这些小程序采用 WeApp-Workflow 作为开发工作流（欢迎发PR 添加案例）：\n\n![devework+微信小程序](src/assets/images/qr-r.jpg)\n\n## 鸣谢\n\n[tmt-workflow](https://github.com/Tencent/tmt-workflow)\n\n[QMUI_Web](https://github.com/QMUI/QMUI_Web)\n\n[postcss-lazysprite](https://github.com/Jeff2Ma/postcss-lazysprite)\n\n[gulp-qcloud-upload](https://github.com/Jeff2Ma/gulp-qcloud-upload)\n\n\n\n## TODO\n\n- [ ] 增加单元测试\n\n- [ ] ES6 Rewrite\n\n- [ ] 上传到FTP/SFTP 服务器功能\n\n- [ ] 支持七牛云存储的CDN\n\n## 意见反馈\n\n如果有意见反馈或者功能建议，欢迎创建 Issue 或发送 Pull Request，感谢你的支持和贡献。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJeff2Ma%2FWeApp-Workflow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FJeff2Ma%2FWeApp-Workflow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJeff2Ma%2FWeApp-Workflow/lists"}