2022-01-08 17:20:46 +08:00
|
|
|
|
import vue from '@vitejs/plugin-vue'
|
2022-02-21 11:25:06 +08:00
|
|
|
|
|
2022-04-08 19:35:22 +08:00
|
|
|
|
/**
|
|
|
|
|
* * 扩展setup插件,支持在script标签中使用name属性
|
|
|
|
|
* usage: <script setup name="MyComp"></script>
|
|
|
|
|
*/
|
|
|
|
|
import VueSetupExtend from 'vite-plugin-vue-setup-extend'
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* * 组件库按需引入插件
|
|
|
|
|
* usage: 直接使用组件,无需在任何地方导入组件
|
|
|
|
|
*/
|
2022-02-21 11:25:06 +08:00
|
|
|
|
import Components from 'unplugin-vue-components/vite'
|
|
|
|
|
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'
|
|
|
|
|
|
2022-04-08 19:35:22 +08:00
|
|
|
|
/**
|
|
|
|
|
* * unplugin-icons插件,自动引入iconify图标
|
|
|
|
|
* usage: https://github.com/antfu/unplugin-icons
|
|
|
|
|
* 图标库: https://icones.js.org/
|
|
|
|
|
*/
|
2022-04-08 17:21:48 +08:00
|
|
|
|
import Icons from 'unplugin-icons/vite'
|
|
|
|
|
|
2022-04-19 21:50:19 +08:00
|
|
|
|
// rollup打包分析插件
|
|
|
|
|
import visualizer from 'rollup-plugin-visualizer'
|
|
|
|
|
|
2022-01-25 16:26:51 +08:00
|
|
|
|
import { unocss } from './unocss'
|
2022-01-08 17:20:46 +08:00
|
|
|
|
import { configHtmlPlugin } from './html'
|
|
|
|
|
import { configMockPlugin } from './mock'
|
|
|
|
|
|
|
|
|
|
export function createVitePlugins(viteEnv, isBuild) {
|
2022-02-21 11:25:06 +08:00
|
|
|
|
const plugins = [
|
|
|
|
|
vue(),
|
2022-04-08 17:21:48 +08:00
|
|
|
|
VueSetupExtend(),
|
2022-02-21 11:25:06 +08:00
|
|
|
|
Components({
|
|
|
|
|
resolvers: [NaiveUiResolver()],
|
|
|
|
|
}),
|
2022-04-08 17:21:48 +08:00
|
|
|
|
Icons({ compiler: 'vue3', autoInstall: true }),
|
2022-02-21 11:25:06 +08:00
|
|
|
|
unocss(),
|
|
|
|
|
configHtmlPlugin(viteEnv, isBuild),
|
|
|
|
|
]
|
2022-01-08 17:20:46 +08:00
|
|
|
|
|
|
|
|
|
viteEnv?.VITE_APP_USE_MOCK && plugins.push(configMockPlugin(isBuild))
|
|
|
|
|
|
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
|
|
|
|
|
}
|