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

50 lines
1.3 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';
import visualizer from 'rollup-plugin-visualizer';
2020-10-28 01:59:37 +08:00
// @ts-ignore
import pkg from '../../../package.json';
2021-01-09 23:28:52 +08:00
import { ViteEnv, isReportMode } from '../../utils';
import { configHtmlPlugin } from './html';
import { configPwaConfig } from './pwa';
import { configMockPlugin } from './mock';
import { configGzipPlugin } from './gzip';
2021-01-18 22:42:35 +08:00
import { configStyleImportConfig } from './style-import';
// gen vite plugins
2021-01-09 23:28:52 +08:00
export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean, mode: string) {
const vitePlugins: (Plugin | Plugin[])[] = [];
// vite-plugin-html
2021-01-09 23:28:52 +08:00
vitePlugins.push(configHtmlPlugin(viteEnv, isBuild));
// vite-plugin-pwa
2021-01-09 23:28:52 +08:00
vitePlugins.push(configPwaConfig(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
vitePlugins.push(configStyleImportConfig());
2021-01-09 23:28:52 +08:00
// rollup-plugin-gzip
vitePlugins.push(configGzipPlugin(isBuild));
2021-01-09 23:28:52 +08:00
// rollup-plugin-visualizer
if (isReportMode()) {
vitePlugins.push(
visualizer({
filename: './build/.cache/stats.html',
open: true,
}) as Plugin
);
}
2021-01-09 23:28:52 +08:00
return vitePlugins;
}