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