123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- import type { Plugin } from 'vite';
- import vue from '@vitejs/plugin-vue';
- import vueJsx from '@vitejs/plugin-vue-jsx';
- import legacy from '@vitejs/plugin-legacy';
- import purgeIcons from 'vite-plugin-purge-icons';
- import windiCSS from 'vite-plugin-windicss';
- import { configHtmlPlugin } from './html';
- import { configPwaConfig } from './pwa';
- import { configMockPlugin } from './mock';
- import { configCompressPlugin } from './compress';
- import { configStyleImportPlugin } from './styleImport';
- import { configVisualizerConfig } from './visualizer';
- import { configThemePlugin } from './theme';
- import { configImageminPlugin } from './imagemin';
- import { configSvgIconsPlugin } from './svgSprite';
- import { configHmrPlugin } from './hmr';
- export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) {
- const {
- VITE_GLOB_USE_IMAGEMIN,
- VITE_GLOB_USE_MOCK,
- VITE_LEGACY,
- VITE_GLOB_BUILD_COMPRESS,
- VITE_GLOB_BUILD_COMPRESS_DELETE_ORIGIN_FILE,
- } = viteEnv;
- const vitePlugins: (Plugin | Plugin[])[] = [
- // have to
- vue(),
- // have to
- vueJsx(),
- ];
- // vite-plugin-windicss
- vitePlugins.push(windiCSS());
- // TODO
- !isBuild && vitePlugins.push(configHmrPlugin());
- // @vitejs/plugin-legacy
- VITE_LEGACY && isBuild && vitePlugins.push(legacy());
- // vite-plugin-html
- vitePlugins.push(configHtmlPlugin(viteEnv, isBuild));
- // vite-plugin-svg-icons
- vitePlugins.push(configSvgIconsPlugin(isBuild));
- // vite-plugin-mock
- VITE_GLOB_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));
- // The following plugins only work in the production environment
- if (isBuild) {
- //vite-plugin-imagemin
- VITE_GLOB_USE_IMAGEMIN && vitePlugins.push(configImageminPlugin());
- // rollup-plugin-gzip
- vitePlugins.push(
- configCompressPlugin(VITE_GLOB_BUILD_COMPRESS, VITE_GLOB_BUILD_COMPRESS_DELETE_ORIGIN_FILE)
- );
- // vite-plugin-pwa
- vitePlugins.push(configPwaConfig(viteEnv));
- }
- return vitePlugins;
- }
|