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