npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@dafengzhen/vite-plugin-mp

v1.1.12

Published

vite-plugin-mp 使用 Vite 编译微信小程序

Readme

使用 Vite 编译微信小程序

该插件使用 Vite 对原生微信小程序编译

安装插件

请确保你已安装 vite 7

如果还没有安装,请执行:npm install -D vite

npm install -D @dafengzhen/vite-plugin-mp

使用插件

  • 配置插件
import VitePluginMp from '@dafengzhen/vite-plugin-mp';
import { defineConfig } from 'vite';

export default defineConfig({
  plugins: [VitePluginMp()],
});
  • 编译打包
npm run build
  • 输入输出
# 输入
miniprogram
├── app.json
├── app.ts
├── app.wxss
├── pages
│   ├── index
│   │   ├── index.json
│   │   ├── index.ts
│   │   ├── index.wxml
│   │   └── index.wxss
│   └── logs
│       ├── logs.json
│       ├── logs.ts
│       ├── logs.wxml
│       └── logs.wxss
└── utils
    └── util.ts
project.config.json
project.private.config.json
# 输出
dist
├── miniprogram
│    ├── app.js
│    ├── app.json
│    ├── app.wxss
│    ├── pages
│    │   ├── index
│    │   │   ├── index.js
│    │   │   ├── index.json
│    │   │   ├── index.wxml
│    │   │   └── index.wxss
│    │   └── logs
│    │       ├── logs.js
│    │       ├── logs.json
│    │       ├── logs.wxml
│    │       └── logs.wxss
│    └── utils
│        └── util.js
└── project.config.json

插件选项

compress?: (html: string | Uint8Array) => Promise<string | Uint8Array> | string | Uint8Array

自定义函数,用于压缩 HTML 字符串或 Uint8Array 输入

  • 参数
    • html:待压缩的内容,可以是字符串或 Uint8Array
  • 返回值
    • 返回压缩后的内容,可以是同步或异步的 stringUint8Array

配置示例:

import { minify } from 'html-minifier-terser';

compress: (source) => {
  return minify(source as string, {
    caseSensitive: true,
    collapseBooleanAttributes: true,
    collapseWhitespace: true,
    conservativeCollapse: true,
    ignoreCustomFragments: [/\{\{[\s\S]*?}}/],
    keepClosingSlash: true,
    removeComments: true,
    removeEmptyAttributes: true,
    removeOptionalTags: true,
    removeRedundantAttributes: true,
    sortAttributes: true,
    sortClassName: true,
  });
}

debug?: boolean

是否启用详细日志输出,仅有被复制匹配的文件才有日志输出

  • 默认值false

isTsProject?: boolean

是否为 TypeScript 项目

  • 默认值true

jsonIgnore?: string | string[]

指定要排除处理的 JSON 文件或目录的 glob 匹配模式

jsonInclude?: string | string[]

指定要包含处理的 JSON 文件或目录的 glob 匹配模式

配置示例:

jsonInclude: ['project.private.config.json']

outputDir?: string

输出目录,相对于项目根目录

  • 默认值"miniprogram"

rootDir?: string

用于解析文件路径的根目录

  • 默认值"miniprogram"

targets?: { src: string; dest: string; }[]

要复制的目标列表

每个对象代表一个复制规则:

  • src: 相对于 rootDir 的源文件 glob 匹配模式
  • dest: 相对于 outputDir 的目标目录,匹配的文件将被复制到此目录中

配置示例:

targets: [
  {
    dest: 'assets',
    src: 'assets/**/*.txt',
  },
]

rpxToVw?: boolean

是否启用将 rpx 自动转换为 vw 的功能

仅对 wxss 样式文件有效

  • 默认值false

designWidth?: number

设计稿的宽度,通常用于将 rpx 单位转换为 vw 单位时的基准宽度

例如,在 750 的设计稿下,1rpx = 0.133vw(100 / 750)

  • 默认值750

其他问题

  • 适用场景

    原生微信小程序

  • 插件版本

    基于 vite 7 编写

  • 使用示例

    参考 examples 下的 miniprogram,使用的是微信小程序 ts 基础模版

  • 运行项目

    构建完成,会生成 dist 目录,打开微信小程序开发者工具,选择 dist 目录导入

  • 目录结构

    一个小程序页面由四个文件组成,分别是:

    | 文件类型 | 必需 | 作用 | |----------|------|------------| | js | 是 | 页面逻辑 | | wxml | 是 | 页面结构 | | json | 否 | 页面配置 | | wxss | 否 | 页面样式表 |

    描述页面的四个文件应该具有相同的路径与文件名

License

MIT