vben-admin-thin-next/build/vite/plugin/index.ts

83 lines
2.2 KiB
TypeScript
Raw Normal View History

2021-01-09 23:28:52 +08:00
import type { Plugin } from 'vite';
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';
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';
import { configCompressPlugin } from './compress';
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';
import { configWindiCssPlugin } from './windicss';
2021-03-05 23:12:01 +08:00
import { configSvgIconsPlugin } from './svgSprite';
import { configHmrPlugin } from './hmr';
2021-01-30 16:53:00 +08:00
export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) {
const {
VITE_USE_IMAGEMIN,
VITE_USE_MOCK,
VITE_LEGACY,
VITE_BUILD_COMPRESS,
VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE,
} = 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(),
];
// TODO
!isBuild && vitePlugins.push(configHmrPlugin());
2021-02-09 23:47:14 +08:00
// @vitejs/plugin-legacy
VITE_LEGACY && isBuild && vitePlugins.push(legacy());
// vite-plugin-html
2021-01-09 23:28:52 +08:00
vitePlugins.push(configHtmlPlugin(viteEnv, isBuild));
2021-03-05 23:12:01 +08:00
// vite-plugin-svg-icons
vitePlugins.push(configSvgIconsPlugin(isBuild));
// vite-plugin-windicss
vitePlugins.push(configWindiCssPlugin());
// 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
// vite-plugin-purge-icons
vitePlugins.push(PurgeIcons());
2021-01-18 22:42:35 +08:00
// vite-plugin-style-import
vitePlugins.push(configStyleImportPlugin(isBuild));
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
2021-04-07 23:14:51 +08:00
vitePlugins.push(configThemePlugin(isBuild));
2021-02-03 23:52:55 +08:00
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
vitePlugins.push(
configCompressPlugin(VITE_BUILD_COMPRESS, VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE)
);
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;
}