1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- import { PluginOption } from 'vite';
- import vue from '@vitejs/plugin-vue';
- import vueJsx from '@vitejs/plugin-vue-jsx';
- import purgeIcons from 'vite-plugin-purge-icons';
- import UnoCSS from 'unocss/vite';
- import { presetTypography, presetUno } from 'unocss';
- import VitePluginCertificate from 'vite-plugin-mkcert';
- //[issues/555]开发环境,vscode断点调试,文件或行数对不上
- import vueSetupExtend from 'vite-plugin-vue-setup-extend-plus';
- import { configHtmlPlugin } from './html';
- import { configMockPlugin } from './mock';
- import { configCompressPlugin } from './compress';
- import { configStyleImportPlugin } from './styleImport';
- import { configVisualizerConfig } from './visualizer';
- import { configThemePlugin } from './theme';
- import { configSvgIconsPlugin } from './svgSprite';
- import { configServerPlugin } from './serveStatic';
- // //预编译加载插件(不支持vite3作废)
- // import OptimizationPersist from 'vite-plugin-optimize-persist';
- import { resolve } from 'path';
- import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
- import topLevelAwait from 'vite-plugin-top-level-await';
- export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) {
- const { VITE_USE_MOCK, VITE_BUILD_COMPRESS, VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE } = viteEnv;
- const vitePlugins: (PluginOption | PluginOption[])[] = [
- // have to
- vue(),
- // have to
- vueJsx(),
- // support name
- vueSetupExtend(),
- // @ts-ignore
- VitePluginCertificate({
- source: 'coding',
- }),
- createSvgIconsPlugin({
- // 指定需要缓存的图标文件夹
- iconDirs: [resolve(process.cwd(), 'src/assets/icons')],
- // 指定symbolId格式
- symbolId: 'svg-[name]',
- // 禁用压缩 否则想要修改无状态组件的stroke或者fill会影响到预设样式 例如stroke-width
- svgoOptions: false,
- customDomId: '__webtopo__svgpreview__icons__dom__',
- }),
- topLevelAwait({
- // The export name of top-level await promise for each chunk module
- promiseExportName: '__tla',
- // The function to generate import names of top-level await promise in each chunk module
- promiseImportName: (i) => `__tla_${i}`,
- }),
- ];
- vitePlugins.push(UnoCSS({ presets: [presetUno(), presetTypography()] }));
- // vite-plugin-html
- vitePlugins.push(configHtmlPlugin(viteEnv, isBuild));
- // vite-plugin-svg-icons
- vitePlugins.push(configSvgIconsPlugin(isBuild));
- // vite-plugin-mock
- VITE_USE_MOCK && vitePlugins.push(configMockPlugin(isBuild));
- // vite-plugin-purge-icons
- vitePlugins.push(purgeIcons());
- // vite-plugin-style-import
- vitePlugins.push(configStyleImportPlugin(isBuild));
- // rollup-plugin-visualizer
- vitePlugins.push(configVisualizerConfig());
- // vite-plugin-theme
- vitePlugins.push(configThemePlugin(isBuild));
- // vite-plugin-serve-static
- vitePlugins.push(configServerPlugin());
- // 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-theme【预编译加载插件,解决vite首次打开界面加载慢问题】
- // vitePlugins.push(PkgConfig());
- // vitePlugins.push(OptimizationPersist());
- return vitePlugins;
- }
|