vben
authored
|
1
|
import type { Plugin } from 'vite';
|
vben
authored
|
2
3
4
|
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import legacy from '@vitejs/plugin-legacy';
|
vben
authored
|
5
|
import purgeIcons from 'vite-plugin-purge-icons';
|
Vben
authored
|
6
|
import windiCSS from 'vite-plugin-windicss';
|
vben
authored
|
7
|
import vueSetupExtend from 'vite-plugin-vue-setup-extend';
|
vben
authored
|
8
9
10
|
import { configHtmlPlugin } from './html';
import { configPwaConfig } from './pwa';
import { configMockPlugin } from './mock';
|
vben
authored
|
11
|
import { configCompressPlugin } from './compress';
|
vben
authored
|
12
|
import { configStyleImportPlugin } from './styleImport';
|
vben
authored
|
13
|
import { configVisualizerConfig } from './visualizer';
|
vben
authored
|
14
|
import { configThemePlugin } from './theme';
|
vben
authored
|
15
|
import { configImageminPlugin } from './imagemin';
|
Vben
authored
|
16
|
import { configSvgIconsPlugin } from './svgSprite';
|
Vben
authored
|
17
|
import { configHmrPlugin } from './hmr';
|
vben
authored
|
18
|
|
vben
authored
|
19
|
export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) {
|
|
20
21
22
23
24
25
26
|
const {
VITE_USE_IMAGEMIN,
VITE_USE_MOCK,
VITE_LEGACY,
VITE_BUILD_COMPRESS,
VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE,
} = viteEnv;
|
vben
authored
|
27
|
|
vben
authored
|
28
29
30
31
32
|
const vitePlugins: (Plugin | Plugin[])[] = [
// have to
vue(),
// have to
vueJsx(),
|
vben
authored
|
33
34
|
// support name
vueSetupExtend(),
|
vben
authored
|
35
36
|
];
|
Vben
authored
|
37
38
39
|
// vite-plugin-windicss
vitePlugins.push(windiCSS());
|
Vben
authored
|
40
|
// TODO
|
Vben
authored
|
41
|
!isBuild && vitePlugins.push(configHmrPlugin());
|
Vben
authored
|
42
|
|
vben
authored
|
43
|
// @vitejs/plugin-legacy
|
vben
authored
|
44
|
VITE_LEGACY && isBuild && vitePlugins.push(legacy());
|
vben
authored
|
45
46
|
// vite-plugin-html
|
vben
authored
|
47
48
|
vitePlugins.push(configHtmlPlugin(viteEnv, isBuild));
|
Vben
authored
|
49
50
51
|
// vite-plugin-svg-icons
vitePlugins.push(configSvgIconsPlugin(isBuild));
|
vben
authored
|
52
|
// vite-plugin-mock
|
vben
authored
|
53
|
VITE_USE_MOCK && vitePlugins.push(configMockPlugin(isBuild));
|
vben
authored
|
54
|
|
vben
authored
|
55
|
// vite-plugin-purge-icons
|
vben
authored
|
56
|
vitePlugins.push(purgeIcons());
|
vben
authored
|
57
|
|
vben
authored
|
58
|
// vite-plugin-style-import
|
Vben
authored
|
59
|
vitePlugins.push(configStyleImportPlugin(isBuild));
|
vben
authored
|
60
|
|
vben
authored
|
61
|
// rollup-plugin-visualizer
|
vben
authored
|
62
|
vitePlugins.push(configVisualizerConfig());
|
vben
authored
|
63
|
|
|
64
|
// vite-plugin-theme
|
Vben
authored
|
65
|
vitePlugins.push(configThemePlugin(isBuild));
|
vben
authored
|
66
|
|
vben
authored
|
67
|
// The following plugins only work in the production environment
|
vben
authored
|
68
|
if (isBuild) {
|
|
69
|
// vite-plugin-imagemin
|
vben
authored
|
70
|
VITE_USE_IMAGEMIN && vitePlugins.push(configImageminPlugin());
|
vben
authored
|
71
72
|
// rollup-plugin-gzip
|
|
73
|
vitePlugins.push(
|
vben
authored
|
74
|
configCompressPlugin(VITE_BUILD_COMPRESS, VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE),
|
|
75
|
);
|
vben
authored
|
76
77
78
79
80
|
// vite-plugin-pwa
vitePlugins.push(configPwaConfig(viteEnv));
}
|
vben
authored
|
81
|
return vitePlugins;
|
vben
authored
|
82
|
}
|