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