需要插件rollup-plugin-compression
在vite.config中使用
import compresssionBuild from 'rollup-plugin-compression'
import type { ICompressionOptions } from 'rollup-plugin-compression'
import dayjs from 'dayjs'
import packageInfo from './package.json'
const option: ICompressionOptions = {
sourceName: `dist`, //要打包的目录
type: 'zip', //打包的后缀
targetName: `${packageInfo.name.replace('-', '_')}${dayjs(new Date()).format(
'YYYYMMDDHHmmss'
)}`, //打包后的包名,根据需要自行修改
ignoreBase: true //默认打包源文件夹本身,配置为true则只打包文件夹内文件
}
export default defineConfig({
plugins: [
compresssionBuild(option)
],
})
打包运行npm run build