vite-plugin-build-pack
v1.0.0
Published
Vite plugin: clean output by glob, zip build dir (name-version.zip), auto-increment version in build.config.json
Maintainers
Readme
vite-plugin-build-pack
Vite 插件:打包完成后清理输出目录指定文件(支持 glob)、自动打 zip(如 name-0.0.0.zip)、版本号自增(每次打包末位 +1,写回 build.config.json)。也可仅使用清理能力。
安装
npm i vite-plugin-build-pack
# or
pnpm add vite-plugin-build-pack
# or
yarn add vite-plugin-build-pack一、打包 + 压缩(buildPack)
打包成功后自动生成 {name}-{version}.zip,每次打包将版本末位 +1 并写回 build.config.json。
1. 项目根目录配置文件(推荐)
在项目根目录新建 build.config.json:
{
"name": "my-app",
"version": "0.0.0",
"cleanOutput": {
"patterns": ["**/.DS_Store", "**/index.html"],
"verbose": true
}
}- name(可选):zip 文件名前缀。不配置则使用打包输出目录名(如
dist、dist-admin-renda-meet-flow)。 - version(可选):版本,默认
"0.0.0"。每次打包后末位 +1 并写回本文件。 - cleanOutput(可选):打包前/后按 glob 删除输出目录中的文件。
vite.config.ts 中:
import { defineConfig } from 'vite'
import { buildPack } from 'vite-plugin-build-pack'
export default defineConfig({
plugins: [
buildPack({ configPath: 'build.config.json' }),
],
})2. 全部在 Vite 里配置
也可以不建 build.config.json,在插件参数里写完整配置:
buildPack({
name: 'my-app', // 可选,默认用输出目录名
version: '0.0.0', // 可选,默认 0.0.0
configPath: 'build.config.json', // 可选,版本在此文件中读写
zip: true, // 可选,是否打 zip,默认 true
cleanOutput: {
patterns: ['**/.DS_Store', '**/*.map'],
verbose: true,
},
}),行为说明
- name:未配置时用
config.build.outDir的目录名(如dist→ zip 名为dist-0.0.0.zip)。 - version:从
build.config.json读取,默认"0.0.0";每次打包后末位 +1 并写回该文件。 - zip 生成在项目根目录,如
my-app-0.0.1.zip。
二、仅清理输出(cleanOutput)
只做「按 glob 删除输出目录文件」,不打 zip、不碰版本:
import { cleanOutput } from 'vite-plugin-build-pack'
cleanOutput({
patterns: ['**/.DS_Store', '**/*.map'],
verbose: true,
}),Glob 模式
**:任意层级目录*:单层?、[a-z]、{a,b}等均支持
示例:**/.DS_Store、**/*.map、**/index.html。
发布到 npm
cd vite-plugin-build-pack
pnpm install
pnpm run build
npm publishLicense
MIT
