admin-vben/build/vite/plugin/index.ts

54 lines
1.5 KiB
TypeScript
Raw Normal View History

2023-07-29 10:46:43 +00:00
import type { PluginOption } from 'vite'
2023-03-18 13:10:54 +00:00
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import progress from 'vite-plugin-progress'
import purgeIcons from 'vite-plugin-purge-icons'
import VitePluginCertificate from 'vite-plugin-mkcert'
2023-07-29 10:46:43 +00:00
import UnoCSS from 'unocss/vite'
2023-03-18 13:10:54 +00:00
import { configPwaConfig } from './pwa'
2023-03-23 06:05:19 +00:00
import { configHtmlPlugin } from './html'
2023-03-18 13:10:54 +00:00
import { configCompressPlugin } from './compress'
import { configVisualizerConfig } from './visualizer'
import { configSvgIconsPlugin } from './svgSprite'
2023-07-29 12:20:40 +00:00
export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) {
2023-03-27 08:56:57 +00:00
const { VITE_BUILD_COMPRESS, VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE } = viteEnv
2023-03-18 13:10:54 +00:00
2023-04-14 06:50:05 +00:00
const vitePlugins: PluginOption[] = [
2023-03-18 13:10:54 +00:00
// have to
vue(),
// have to
vueJsx(),
2023-07-29 08:40:09 +00:00
// UnoCSS
2023-09-06 08:55:22 +00:00
UnoCSS(),
2023-03-18 13:10:54 +00:00
// 打包进度条
progress(),
VitePluginCertificate({
2023-07-29 10:46:43 +00:00
source: 'coding',
}),
2023-03-18 13:10:54 +00:00
]
2023-03-24 09:39:26 +00:00
// vite-vue-plugin-html
2023-03-23 06:05:19 +00:00
vitePlugins.push(configHtmlPlugin(viteEnv, isBuild))
2023-03-18 13:10:54 +00:00
// vite-plugin-svg-icons
vitePlugins.push(configSvgIconsPlugin(isBuild))
// vite-plugin-purge-icons
vitePlugins.push(purgeIcons())
// rollup-plugin-visualizer
vitePlugins.push(configVisualizerConfig())
// The following plugins only work in the production environment
if (isBuild) {
// rollup-plugin-gzip
vitePlugins.push(configCompressPlugin(VITE_BUILD_COMPRESS, VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE))
// vite-plugin-pwa
vitePlugins.push(configPwaConfig(viteEnv))
}
return vitePlugins
}