{"id":23385456,"url":"https://github.com/dafengzhen/vite-plugin-mp","last_synced_at":"2025-04-08T11:47:26.566Z","repository":{"id":214759134,"uuid":"737288332","full_name":"dafengzhen/vite-plugin-mp","owner":"dafengzhen","description":"使用 Vite 编译微信小程序","archived":false,"fork":false,"pushed_at":"2023-12-30T15:25:45.000Z","size":23,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-29T20:59:49.328Z","etag":null,"topics":["mini-programs","mp","plugin","rollup","sass","typescript","vite","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}},"created_at":"2023-12-30T13:44:03.000Z","updated_at":"2024-07-15T12:44:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"995dd023-0972-4bca-9edc-ced95a9b18e2","html_url":"https://github.com/dafengzhen/vite-plugin-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"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dafengzhen%2Fvite-plugin-mp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dafengzhen%2Fvite-plugin-mp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dafengzhen%2Fvite-plugin-mp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dafengzhen%2Fvite-plugin-mp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dafengzhen","download_url":"https://codeload.github.com/dafengzhen/vite-plugin-mp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247838421,"owners_count":21004576,"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","rollup","sass","typescript","vite","wechat","weixin","wxml","wxss"],"created_at":"2024-12-22T00:17:33.375Z","updated_at":"2025-04-08T11:47:26.540Z","avatar_url":"https://github.com/dafengzhen.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 使用 Vite 编译微信小程序\n\n当你想使用原生微信小程序开发，不想使用其他框架进行开发，只想简单的使用 Vite 进行编译打包，那么这就是该插件用途\n\n注意使用版本，该插件测试的为微信小程序基于 Skyline 渲染引擎的 Ts + Scss 模板，以及 Vite 5\n\n# 安装依赖\n\n```bash\nnpm install -D glob rollup-plugin-copy @dafengzhen/vite-plugin-mp\n```\n\n# 使用插件\n\n- **编辑 ```vite.config.ts``` 文件**\n\n```javascript\nimport path from \"path\";\nimport VitePluginMp from '@dafengzhen/vite-plugin-mp';\nimport {defineConfig} from 'vite';\n\nexport default defineConfig({\n    plugins: [\n        VitePluginMp({\n            buildDir: path.resolve(__dirname, 'miniprogram'),\n            outputDir: path.resolve(__dirname, 'dist')\n        })\n    ]\n})\n```\n\n- **构建编译小程序**\n\n```bash\nnpm run build\n```\n\n- **输入输出示例**\n\n这里省略多余的文件，只展示关键信息\n\n输入的代码结构：\n\n```text\n├── ...\n├── miniprogram\n│   ├── apis\n│   │   └── test\n│   │       └── index.ts\n│   ├── app.json\n│   ├── app.scss\n│   ├── app.ts\n│   ├── assets\n│   │   ├── images\n│   │   │   ├── test.png\n│   ├── components\n│   │   └── navigation-bar\n│   │       ├── navigation-bar.json\n│   │       ├── navigation-bar.scss\n│   │       ├── navigation-bar.ts\n│   │       └── navigation-bar.wxml\n│   ├── constants\n│   │   └── index.ts\n│   ├── interfaces\n│   │   └── index.ts\n│   ├── pages\n│   │   ├── index\n│   │   │   ├── index.json\n│   │   │   ├── index.scss\n│   │   │   ├── index.ts\n│   │   │   └── index.wxml\n│   ├── sitemap.json\n│   └── tools\n│       ├── index.ts\n│       ├── request.ts\n│       └── upload-request.ts\n├── project.config.json\n├── project.private.config.json\n└── ...\n```\n\n输出的代码结构：\n\n```text\n├── ...\n├── dist\n│   ├── miniprogram\n│   │   ├── apis\n│   │   │   └── test\n│   │   │       └── index.js\n│   │   ├── app.js\n│   │   ├── app.json\n│   │   ├── app.wxss\n│   │   ├── assets\n│   │   │   ├── images\n│   │   │   │   ├── test.png\n│   │   ├── components\n│   │   │   └── navigation-bar\n│   │   │       ├── navigation-bar.js\n│   │   │       ├── navigation-bar.json\n│   │   │       ├── navigation-bar.wxml\n│   │   │       └── navigation-bar.wxss\n│   │   ├── constants\n│   │   │   └── index.js\n│   │   ├── pages\n│   │   │   ├── index\n│   │   │   │   ├── index.js\n│   │   │   │   ├── index.json\n│   │   │   │   ├── index.wxml\n│   │   │   │   └── index.wxss\n│   │   ├── sitemap.json\n│   │   └── tools\n│   │       ├── index.js\n│   │       ├── request.js\n│   │       └── upload-request.js\n│   ├── project.config.json\n│   └── project.private.config.json\n└── ...\n```\n\n# 插件选项\n\n- **buildDir** 必填。编译小程序的代码目录\n- **outputDir** 必填。输出编译小程序的代码目录\n- **processedDir** 可选。要处理的代码文件夹名称，默认为 ```['apis', 'components', 'constants', 'pages', 'tools']```\n- **processedAssetDir** 可选。要处理的资源文件夹名称，默认为 ```['assets']```\n\n# 其他相关\n\n- 当不要想使用该插件，如何将原来代码转换为使用 Uni-App / Taro 等框架开发\n\n该插件使用的对象为微信原生小程序，意味着如果需要转化为其他框架，可以从 \"微信原生小程序如何转换 XXX 框架\" 为出发点，这是一种方式\n\n另一种方式是使用框架本身提供的转换工具，尝试转换微信小程序，例如 [Uni-App 转换工具指南](https://zh.uniapp.dcloud.io/translate.html) 等\n\n- 当使用该插件遇到无法编译，或者发生未知错误，想改为原来的微信小程序需要如何做\n\n首先要做的是移除该插件，因为该插件本质上只是使用 Vite 来对文件进行编译而已\n\n其次，即使不使用 Vite，微信开发者工具也能进行编译，除此之外没有太大区别\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-mp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdafengzhen%2Fvite-plugin-mp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdafengzhen%2Fvite-plugin-mp/lists"}