vue-vben-admin/build/vite/plugin/index.ts

52 lines
1.4 KiB
TypeScript
Raw Normal View History

2021-01-09 23:28:52 +08:00
import type { Plugin } from 'vite';
import PurgeIcons from 'vite-plugin-purge-icons';
2020-10-28 01:59:37 +08:00
// @ts-ignore
import pkg from '../../../package.json';
import { ViteEnv } from '../../utils';
2021-01-09 23:28:52 +08:00
import { configHtmlPlugin } from './html';
import { configPwaConfig } from './pwa';
import { configMockPlugin } from './mock';
import { configGzipPlugin } from './gzip';
2021-02-03 23:52:55 +08:00
import { configStyleImportPlugin } from './styleImport';
import { configVisualizerConfig } from './visualizer';
2021-02-03 23:52:55 +08:00
import { configThemePlugin } from './theme';
2021-02-04 22:00:25 +08:00
import { configImageminPlugin } from './imagemin';
// gen vite plugins
2021-01-30 16:53:00 +08:00
export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) {
2021-01-09 23:28:52 +08:00
const vitePlugins: (Plugin | Plugin[])[] = [];
// vite-plugin-html
2021-01-09 23:28:52 +08:00
vitePlugins.push(configHtmlPlugin(viteEnv, isBuild));
// vite-plugin-mock
2021-01-09 23:28:52 +08:00
vitePlugins.push(configMockPlugin(viteEnv, isBuild));
// vite-plugin-purge-icons
vitePlugins.push(PurgeIcons());
2021-01-18 22:42:35 +08:00
// vite-plugin-style-import
2021-02-03 23:52:55 +08:00
vitePlugins.push(configStyleImportPlugin());
2021-01-18 22:42:35 +08:00
2021-01-09 23:28:52 +08:00
// rollup-plugin-visualizer
vitePlugins.push(configVisualizerConfig());
2021-02-03 23:52:55 +08:00
//vite-plugin-theme
vitePlugins.push(configThemePlugin());
2021-02-04 22:00:25 +08:00
if (isBuild) {
//vite-plugin-imagemin
viteEnv.VITE_USE_IMAGEMIN && vitePlugins.push(configImageminPlugin());
// rollup-plugin-gzip
vitePlugins.push(configGzipPlugin(isBuild));
// vite-plugin-pwa
vitePlugins.push(configPwaConfig(viteEnv));
}
2021-01-09 23:28:52 +08:00
return vitePlugins;
}