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

60 lines
1.7 KiB
TypeScript
Raw Normal View History

2022-02-28 00:21:26 +08:00
import { PluginOption } from 'vite';
2021-02-09 23:47:14 +08:00
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
2021-06-01 21:30:56 +08:00
import purgeIcons from 'vite-plugin-purge-icons';
import windiCSS from 'vite-plugin-windicss';
2022-01-18 22:05:51 +08:00
import VitePluginCertificate from 'vite-plugin-mkcert';
2021-01-09 23:28:52 +08:00
import { configHtmlPlugin } from './html';
import { configMockPlugin } from './mock';
import { configCompressPlugin } from './compress';
import { configVisualizerConfig } from './visualizer';
2021-02-03 23:52:55 +08:00
import { configThemePlugin } from './theme';
2021-03-05 23:12:01 +08:00
import { configSvgIconsPlugin } from './svgSprite';
2021-01-30 16:53:00 +08:00
export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) {
const { VITE_USE_MOCK, VITE_BUILD_COMPRESS, VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE } = viteEnv;
2021-02-08 23:59:47 +08:00
2022-02-28 00:21:26 +08:00
const vitePlugins: (PluginOption | PluginOption[])[] = [
2021-02-09 23:47:14 +08:00
// have to
vue(),
// have to
vueJsx(),
// support name
//vueSetupExtend(),
2022-01-18 22:05:51 +08:00
VitePluginCertificate({
source: 'coding',
}),
2021-02-09 23:47:14 +08:00
];
// vite-plugin-windicss
vitePlugins.push(windiCSS());
// 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-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
2021-06-01 21:30:56 +08:00
vitePlugins.push(purgeIcons());
2021-01-09 23:28:52 +08:00
// rollup-plugin-visualizer
vitePlugins.push(configVisualizerConfig());
// 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) {
// rollup-plugin-gzip
vitePlugins.push(
2021-08-24 22:41:48 +08:00
configCompressPlugin(VITE_BUILD_COMPRESS, VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE),
);
2021-02-04 22:00:25 +08:00
}
2021-01-09 23:28:52 +08:00
return vitePlugins;
}