2023-03-18 13:10:54 +00:00
|
|
|
import { PluginOption } from 'vite'
|
|
|
|
import vue from '@vitejs/plugin-vue'
|
2023-03-24 15:42:18 +00:00
|
|
|
import Unocss from 'unocss/vite'
|
2023-03-18 13:10:54 +00:00
|
|
|
import vueJsx from '@vitejs/plugin-vue-jsx'
|
|
|
|
import legacy from '@vitejs/plugin-legacy'
|
|
|
|
import progress from 'vite-plugin-progress'
|
|
|
|
import purgeIcons from 'vite-plugin-purge-icons'
|
|
|
|
import VitePluginCertificate from 'vite-plugin-mkcert'
|
|
|
|
import vueSetupExtend from 'unplugin-vue-setup-extend-plus/vite'
|
|
|
|
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 { configStyleImportPlugin } from './styleImport'
|
|
|
|
import { configVisualizerConfig } from './visualizer'
|
|
|
|
import { configThemePlugin } from './theme'
|
|
|
|
import { configSvgIconsPlugin } from './svgSprite'
|
|
|
|
import { isProdFn } from '../../utils'
|
|
|
|
|
|
|
|
export function createVitePlugins(mode: string, viteEnv: ViteEnv, isBuild: boolean) {
|
2023-03-18 13:21:41 +00:00
|
|
|
const { VITE_LEGACY, VITE_BUILD_COMPRESS, VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE } = viteEnv
|
2023-03-18 13:10:54 +00:00
|
|
|
|
|
|
|
const vitePlugins: (PluginOption | PluginOption[])[] = [
|
|
|
|
// have to
|
|
|
|
vue(),
|
|
|
|
// have to
|
|
|
|
vueJsx(),
|
|
|
|
// 打包进度条
|
|
|
|
progress(),
|
|
|
|
// support name
|
|
|
|
vueSetupExtend({}),
|
|
|
|
VitePluginCertificate({
|
|
|
|
source: 'coding'
|
|
|
|
})
|
|
|
|
]
|
|
|
|
|
2023-03-24 15:42:18 +00:00
|
|
|
// Unocss
|
|
|
|
vitePlugins.push(Unocss())
|
2023-03-18 13:10:54 +00:00
|
|
|
|
|
|
|
// @vitejs/plugin-legacy
|
|
|
|
VITE_LEGACY && isBuild && vitePlugins.push(legacy())
|
|
|
|
|
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())
|
|
|
|
|
2023-03-25 08:25:45 +00:00
|
|
|
// vite-plugin-style-import
|
2023-03-18 13:10:54 +00:00
|
|
|
if (isProdFn(mode)) {
|
|
|
|
vitePlugins.push(configStyleImportPlugin(isBuild))
|
|
|
|
}
|
|
|
|
|
|
|
|
// rollup-plugin-visualizer
|
|
|
|
vitePlugins.push(configVisualizerConfig())
|
|
|
|
|
|
|
|
// vite-plugin-vben-theme
|
|
|
|
vitePlugins.push(configThemePlugin(isBuild))
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|