vben-admin-thin-next/build/vite/plugin/index.ts
2021-02-08 23:59:47 +08:00

52 lines
1.4 KiB
TypeScript

import type { Plugin } from 'vite';
import PurgeIcons from 'vite-plugin-purge-icons';
import { ViteEnv } from '../../utils';
import { configHtmlPlugin } from './html';
import { configPwaConfig } from './pwa';
import { configMockPlugin } from './mock';
import { configGzipPlugin } from './gzip';
import { configStyleImportPlugin } from './styleImport';
import { configVisualizerConfig } from './visualizer';
import { configThemePlugin } from './theme';
import { configImageminPlugin } from './imagemin';
// gen vite plugins
export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) {
const { VITE_USE_IMAGEMIN, VITE_USE_MOCK } = viteEnv;
const vitePlugins: (Plugin | Plugin[])[] = [];
// vite-plugin-html
vitePlugins.push(configHtmlPlugin(viteEnv, 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());
// rollup-plugin-visualizer
vitePlugins.push(configVisualizerConfig());
//vite-plugin-theme
vitePlugins.push(configThemePlugin());
if (isBuild) {
//vite-plugin-imagemin
VITE_USE_IMAGEMIN && vitePlugins.push(configImageminPlugin());
// rollup-plugin-gzip
vitePlugins.push(configGzipPlugin(isBuild));
// vite-plugin-pwa
vitePlugins.push(configPwaConfig(viteEnv));
}
return vitePlugins;
}