2021-01-09 23:28:52 +08:00
|
|
|
import type { Plugin } from 'vite';
|
2021-02-25 20:17:08 +08:00
|
|
|
import type { ViteEnv } from '../../utils';
|
2020-10-27 21:21:14 +08:00
|
|
|
|
2021-02-09 23:47:14 +08:00
|
|
|
import vue from '@vitejs/plugin-vue';
|
|
|
|
import vueJsx from '@vitejs/plugin-vue-jsx';
|
|
|
|
import legacy from '@vitejs/plugin-legacy';
|
2020-10-27 21:21:14 +08:00
|
|
|
|
2021-02-17 22:07:22 +08:00
|
|
|
import PurgeIcons from 'vite-plugin-purge-icons';
|
|
|
|
|
2021-01-09 23:28:52 +08:00
|
|
|
import { configHtmlPlugin } from './html';
|
|
|
|
import { configPwaConfig } from './pwa';
|
|
|
|
import { configMockPlugin } from './mock';
|
2021-02-13 00:26:41 +08:00
|
|
|
import { configCompressPlugin } from './compress';
|
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';
|
2021-02-18 21:02:56 +08:00
|
|
|
import { configWindiCssPlugin } from './windicss';
|
2020-10-27 21:21:14 +08:00
|
|
|
|
2021-01-30 16:53:00 +08:00
|
|
|
export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) {
|
2021-02-13 00:26:41 +08:00
|
|
|
const { VITE_USE_IMAGEMIN, VITE_USE_MOCK, VITE_LEGACY, VITE_BUILD_COMPRESS } = viteEnv;
|
2021-02-08 23:59:47 +08:00
|
|
|
|
2021-02-09 23:47:14 +08:00
|
|
|
const vitePlugins: (Plugin | Plugin[])[] = [
|
|
|
|
// have to
|
|
|
|
vue(),
|
|
|
|
// have to
|
|
|
|
vueJsx(),
|
|
|
|
];
|
|
|
|
|
|
|
|
// @vitejs/plugin-legacy
|
|
|
|
VITE_LEGACY && isBuild && vitePlugins.push(legacy());
|
2020-10-27 21:21:14 +08:00
|
|
|
|
|
|
|
// vite-plugin-html
|
2021-01-09 23:28:52 +08:00
|
|
|
vitePlugins.push(configHtmlPlugin(viteEnv, isBuild));
|
|
|
|
|
2021-02-18 21:02:56 +08:00
|
|
|
// vite-plugin-windicss
|
|
|
|
vitePlugins.push(configWindiCssPlugin());
|
|
|
|
|
2020-12-13 21:17:37 +08:00
|
|
|
// vite-plugin-mock
|
2021-02-08 23:59:47 +08:00
|
|
|
VITE_USE_MOCK && vitePlugins.push(configMockPlugin(isBuild));
|
2021-01-09 23:28:52 +08:00
|
|
|
|
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-09 23:47:14 +08:00
|
|
|
// The following plugins only work in the production environment
|
2021-02-04 22:00:25 +08:00
|
|
|
if (isBuild) {
|
|
|
|
//vite-plugin-imagemin
|
2021-02-08 23:59:47 +08:00
|
|
|
VITE_USE_IMAGEMIN && vitePlugins.push(configImageminPlugin());
|
2021-02-04 22:00:25 +08:00
|
|
|
|
|
|
|
// rollup-plugin-gzip
|
2021-02-13 00:26:41 +08:00
|
|
|
vitePlugins.push(configCompressPlugin(VITE_BUILD_COMPRESS));
|
2021-02-04 22:00:25 +08:00
|
|
|
|
|
|
|
// 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
|
|
|
}
|