{"id":29412723,"url":"https://github.com/dafengzhen/vite-plugin-wechat-mp","last_synced_at":"2025-07-11T09:39:00.244Z","repository":{"id":214759134,"uuid":"737288332","full_name":"dafengzhen/vite-plugin-wechat-mp","owner":"dafengzhen","description":"使用 Vite 编译微信小程序","archived":false,"fork":false,"pushed_at":"2025-07-05T05:06:47.000Z","size":562,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-05T05:07:43.825Z","etag":null,"topics":["mini-programs","mp","plugin","typescript","vite","vite-plugin","wechat","weixin","wxml","wxss"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/dafengzhen.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-12-30T13:44:03.000Z","updated_at":"2025-07-05T05:06:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"995dd023-0972-4bca-9edc-ced95a9b18e2","html_url":"https://github.com/dafengzhen/vite-plugin-wechat-mp","commit_stats":{"total_commits":4,"total_committers":2,"mean_commits":2.0,"dds":0.25,"last_synced_commit":"e50288d3ece72e9bc094710a372493ec4ec62acd"},"previous_names":["dafengzhen/vite-plugin-mp","dafengzhen/vite-plugin-wechat-mp"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dafengzhen/vite-plugin-wechat-mp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dafengzhen%2Fvite-plugin-wechat-mp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dafengzhen%2Fvite-plugin-wechat-mp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dafengzhen%2Fvite-plugin-wechat-mp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dafengzhen%2Fvite-plugin-wechat-mp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dafengzhen","download_url":"https://codeload.github.com/dafengzhen/vite-plugin-wechat-mp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dafengzhen%2Fvite-plugin-wechat-mp/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264777877,"owners_count":23662556,"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":["mini-programs","mp","plugin","typescript","vite","vite-plugin","wechat","weixin","wxml","wxss"],"created_at":"2025-07-11T09:38:58.885Z","updated_at":"2025-07-11T09:39:00.237Z","avatar_url":"https://github.com/dafengzhen.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## 使用 Vite 编译微信小程序\n\n该插件使用 Vite 对原生微信小程序编译\n\n## 安装插件\n\n请确保你已安装 [vite 7](https://vite.dev/guide/#manual-installation)\n\n如果还没有安装，请执行：```npm install -D vite```\n\n```bash\nnpm install -D vite-plugin-wechat-mp\n```\n\n## 使用插件\n\n- **配置插件**\n\n```javascript\nimport VitePluginWechatMp from 'vite-plugin-wechat-mp';\nimport { defineConfig } from 'vite';\n\nexport default defineConfig({\n  plugins: [VitePluginWechatMp()],\n});\n```\n\n- **编译打包**\n\n```bash\nnpm run build\n```\n\n- **输入输出**\n\n```text\n# 输入\nminiprogram\n├── app.json\n├── app.ts\n├── app.wxss\n├── pages\n│   ├── index\n│   │   ├── index.json\n│   │   ├── index.ts\n│   │   ├── index.wxml\n│   │   └── index.wxss\n│   └── logs\n│       ├── logs.json\n│       ├── logs.ts\n│       ├── logs.wxml\n│       └── logs.wxss\n└── utils\n    └── util.ts\nproject.config.json\nproject.private.config.json\n```\n\n```text\n# 输出\ndist\n├── miniprogram\n│    ├── app.js\n│    ├── app.json\n│    ├── app.wxss\n│    ├── pages\n│    │   ├── index\n│    │   │   ├── index.js\n│    │   │   ├── index.json\n│    │   │   ├── index.wxml\n│    │   │   └── index.wxss\n│    │   └── logs\n│    │       ├── logs.js\n│    │       ├── logs.json\n│    │       ├── logs.wxml\n│    │       └── logs.wxss\n│    └── utils\n│        └── util.js\n└── project.config.json\n```\n\n\u003cimg src=\"images/build.png\" alt=\"build\" style=\"width:60%; height:auto;\"\u003e\n\n## 插件选项\n\n#### `compress?: (html: string | Uint8Array) =\u003e Promise\u003cstring | Uint8Array\u003e | string | Uint8Array`\n\n自定义函数，用于压缩 HTML 字符串或 `Uint8Array` 输入\n\n- **参数**：\n  - `html`：待压缩的内容，可以是字符串或 `Uint8Array`\n- **返回值**：\n  - 返回压缩后的内容，可以是同步或异步的 `string` 或 `Uint8Array`\n\n配置示例：\n```ts\nimport { minify } from 'html-minifier-terser';\n\ncompress: (source) =\u003e {\n  return minify(source as string, {\n    caseSensitive: true,\n    collapseBooleanAttributes: true,\n    collapseWhitespace: true,\n    conservativeCollapse: true,\n    ignoreCustomFragments: [/\\{\\{[\\s\\S]*?}}/],\n    keepClosingSlash: true,\n    removeComments: true,\n    removeEmptyAttributes: true,\n    removeOptionalTags: true,\n    removeRedundantAttributes: true,\n    sortAttributes: true,\n    sortClassName: true,\n  });\n}\n```\n\n#### `debug?: boolean`\n\n是否启用详细日志输出，仅有被复制匹配的文件才有日志输出\n\n- **默认值**：`false`\n\n#### `isTsProject?: boolean`\n\n是否为 TypeScript 项目\n\n- **默认值**：`true`\n\n#### `jsonIgnore?: string | string[]`\n\n指定要排除处理的 JSON 文件或目录的 glob 匹配模式\n\n#### `jsonInclude?: string | string[]`\n\n指定要包含处理的 JSON 文件或目录的 glob 匹配模式\n\n配置示例：\n```ts\njsonInclude: ['project.private.config.json']\n```\n\n#### `outputDir?: string`\n\n输出目录，相对于项目根目录\n\n- **默认值**：`\"miniprogram\"`\n\n#### `rootDir?: string`\n\n用于解析文件路径的根目录\n\n- **默认值**：`\"miniprogram\"`\n\n#### `targets?: { src: string; dest: string; }[]`\n\n要复制的目标列表\n\n每个对象代表一个复制规则：\n\n- `src`: 相对于 `rootDir` 的源文件 glob 匹配模式\n- `dest`: 相对于 `outputDir` 的目标目录，匹配的文件将被复制到此目录中\n\n配置示例：\n```ts\ntargets: [\n  {\n    dest: 'assets',\n    src: 'assets/**/*.txt',\n  },\n]\n```\n\n#### `rpxToVw?: boolean`\n\n是否启用将 rpx 自动转换为 vw 的功能\n\n仅对 wxss 样式文件有效\n\n- **默认值**：`false`\n\n#### `designWidth?: number`\n\n设计稿的宽度，通常用于将 rpx 单位转换为 vw 单位时的基准宽度\n\n例如，在 750 的设计稿下，1rpx = 0.133vw（100 / 750）\n\n- **默认值**：`750`\n\n## 其他问题\n\n- 适用场景\n\n  原生微信小程序\n\n- 插件版本\n\n  基于 vite 7 编写\n\n- 使用示例\n\n  参考 [examples](https://github.com/dafengzhen/vite-plugin-mp/tree/main/examples) 下的 miniprogram，使用的是微信小程序 ts 基础模版\n\n- 运行项目\n\n  构建完成，会生成 ```dist``` 目录，打开微信小程序开发者工具，选择 ```dist``` 目录导入\n\n- [目录结构](https://developers.weixin.qq.com/miniprogram/dev/framework/structure.html)\n\n  一个小程序页面由四个文件组成，分别是：\n\n  | 文件类型 | 必需 | 作用       |\n  |----------|------|------------|\n  | js       | 是   | 页面逻辑   |\n  | wxml     | 是   | 页面结构   |\n  | json     | 否   | 页面配置   |\n  | wxss     | 否   | 页面样式表 |\n\n  描述页面的四个文件应该具有相同的路径与文件名\n\n## License\n\n[MIT](https://opensource.org/licenses/MIT)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdafengzhen%2Fvite-plugin-wechat-mp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdafengzhen%2Fvite-plugin-wechat-mp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdafengzhen%2Fvite-plugin-wechat-mp/lists"}