2021-01-09 23:28:52 +08:00
|
|
|
import type { Plugin } from 'vite';
|
2020-10-27 21:21:14 +08:00
|
|
|
|
|
|
|
import PurgeIcons from 'vite-plugin-purge-icons';
|
|
|
|
|
2020-10-28 01:59:37 +08:00
|
|
|
// @ts-ignore
|
|
|
|
import pkg from '../../../package.json';
|
2021-01-22 22:42:27 +08:00
|
|
|
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';
|
2021-01-22 22:42:27 +08:00
|
|
|
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';
|
2020-10-27 21:21:14 +08:00
|
|
|
|
|
|
|
// 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[])[] = [];
|
2020-10-27 21:21:14 +08:00
|
|
|
|
|
|
|
// vite-plugin-html
|
2021-01-09 23:28:52 +08:00
|
|
|
vitePlugins.push(configHtmlPlugin(viteEnv, isBuild));
|
|
|
|
|
2020-12-13 21:17:37 +08:00
|
|
|
// vite-plugin-mock
|
2021-01-09 23:28:52 +08:00
|
|
|
vitePlugins.push(configMockPlugin(viteEnv, isBuild));
|
|
|
|
|
2020-10-27 21:21:14 +08:00
|
|
|
// 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
|
2021-01-22 22:42:27 +08:00
|
|
|
vitePlugins.push(configVisualizerConfig());
|
2020-12-13 21:17:37 +08:00
|
|
|
|
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;
|
2020-10-27 21:21:14 +08:00
|
|
|
}
|