import type { PluginOption } from 'vite' import Layouts from 'vite-plugin-vue-layouts' import Pages from 'vite-plugin-pages' import WebfontDownload from 'vite-plugin-webfont-dl' import VueDevTools from 'vite-plugin-vue-devtools' import Unocss from 'unocss/vite' import VueI18n from '@intlify/unplugin-vue-i18n/vite' // must import { getRootPath } from 'build/utils' import vueMacros from './vuemacros' import autoImport from './autoimport' import unplugins from './unplugins' // select import visualizer from './visualizer' import compress from './compress' import pwa from './pwa' import markdown from './markdown' export function setupVitePlugins(viteEnv: ImportMetaEnv): (PluginOption | PluginOption[])[] { const plugins = [ vueMacros(), autoImport(), // https://github.com/JohnCampionJr/vite-plugin-vue-layouts Layouts(), // https://github.com/hannoeru/vite-plugin-pages Pages({ extensions: ['vue', 'md'], }), // https://github.com/feat-agency/vite-plugin-webfont-dl WebfontDownload(), // https://github.com/webfansplz/vite-plugin-vue-devtools VueDevTools(), // https://github.com/antfu/unocss // see uno.config.ts for config Unocss(), // https://github.com/intlify/bundle-tools/tree/main/packages/unplugin-vue-i18n VueI18n({ runtimeOnly: true, compositionOnly: true, fullInstall: true, include: [`${getRootPath()}/locales/**`], }), ...unplugins(viteEnv), ] if (viteEnv.VITE_VISUALIZER) plugins.push(visualizer as PluginOption) if (viteEnv.VITE_COMPRESS) plugins.push(compress(viteEnv)) if (viteEnv.VITE_PWA) plugins.push(pwa()) if (viteEnv.VITE_MARKDOWN) plugins.push(markdown(viteEnv)) return plugins }