2022-01-08 17:20:46 +08:00
|
|
|
|
import vue from '@vitejs/plugin-vue'
|
2022-02-21 11:25:06 +08:00
|
|
|
|
|
2022-06-11 16:55:36 +08:00
|
|
|
|
/**
|
|
|
|
|
* * unocss插件,原子css
|
|
|
|
|
* https://github.com/antfu/unocss
|
|
|
|
|
*/
|
|
|
|
|
import Unocss from 'unocss/vite'
|
|
|
|
|
|
2022-04-19 21:50:19 +08:00
|
|
|
|
// rollup打包分析插件
|
|
|
|
|
import visualizer from 'rollup-plugin-visualizer'
|
2022-08-27 11:04:07 +08:00
|
|
|
|
// 压缩
|
|
|
|
|
import viteCompression from 'vite-plugin-compression'
|
2022-04-19 21:50:19 +08:00
|
|
|
|
|
2022-01-08 17:20:46 +08:00
|
|
|
|
import { configHtmlPlugin } from './html'
|
|
|
|
|
import { configMockPlugin } from './mock'
|
2022-06-19 13:35:36 +08:00
|
|
|
|
import unplugin from './unplugin'
|
2022-01-08 17:20:46 +08:00
|
|
|
|
|
|
|
|
|
export function createVitePlugins(viteEnv, isBuild) {
|
2022-09-08 15:08:28 +08:00
|
|
|
|
const plugins = [vue(), ...unplugin, configHtmlPlugin(viteEnv, isBuild), Unocss()]
|
2022-06-19 13:35:36 +08:00
|
|
|
|
|
2022-08-27 14:09:32 +08:00
|
|
|
|
if (viteEnv?.VITE_USE_MOCK) {
|
2022-06-19 13:35:36 +08:00
|
|
|
|
plugins.push(configMockPlugin(isBuild))
|
|
|
|
|
}
|
2022-01-08 17:20:46 +08:00
|
|
|
|
|
2022-08-27 11:04:07 +08:00
|
|
|
|
if (viteEnv.VITE_USE_COMPRESS) {
|
|
|
|
|
plugins.push(viteCompression({ algorithm: viteEnv.VITE_COMPRESS_TYPE || 'gzip' }))
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-19 21:50:19 +08:00
|
|
|
|
if (isBuild) {
|
|
|
|
|
plugins.push(
|
|
|
|
|
visualizer({
|
|
|
|
|
open: true,
|
|
|
|
|
gzipSize: true,
|
|
|
|
|
brotliSize: true,
|
|
|
|
|
})
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-08 17:20:46 +08:00
|
|
|
|
return plugins
|
|
|
|
|
}
|