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) {
|
|
22
23
24
25
26
27
28
|
const {
VITE_USE_IMAGEMIN,
VITE_USE_MOCK,
VITE_LEGACY,
VITE_BUILD_COMPRESS,
VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE,
} = viteEnv;
|
vben
authored
|
29
|
|
vben
authored
|
30
31
32
33
34
35
36
|
const vitePlugins: (Plugin | Plugin[])[] = [
// have to
vue(),
// have to
vueJsx(),
];
|
Vben
authored
|
37
|
// TODO
|
Vben
authored
|
38
|
!isBuild && vitePlugins.push(configHmrPlugin());
|
Vben
authored
|
39
|
|
vben
authored
|
40
41
|
// @vitejs/plugin-legacy
VITE_LEGACY && isBuild && vitePlugins.push(legacy());
|
vben
authored
|
42
43
|
// vite-plugin-html
|
vben
authored
|
44
45
|
vitePlugins.push(configHtmlPlugin(viteEnv, isBuild));
|
Vben
authored
|
46
47
48
|
// vite-plugin-svg-icons
vitePlugins.push(configSvgIconsPlugin(isBuild));
|
vben
authored
|
49
50
51
|
// vite-plugin-windicss
vitePlugins.push(configWindiCssPlugin());
|
vben
authored
|
52
|
// vite-plugin-mock
|
vben
authored
|
53
|
VITE_USE_MOCK && vitePlugins.push(configMockPlugin(isBuild));
|
vben
authored
|
54
|
|
vben
authored
|
55
56
57
|
// vite-plugin-purge-icons
vitePlugins.push(PurgeIcons());
|
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
|
|
vben
authored
|
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
69
|
if (isBuild) {
//vite-plugin-imagemin
|
vben
authored
|
70
|
VITE_USE_IMAGEMIN && vitePlugins.push(configImageminPlugin());
|
vben
authored
|
71
72
|
// rollup-plugin-gzip
|
|
73
74
75
|
vitePlugins.push(
configCompressPlugin(VITE_BUILD_COMPRESS, VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE)
);
|
vben
authored
|
76
77
78
79
80
|
// vite-plugin-pwa
vitePlugins.push(configPwaConfig(viteEnv));
}
|
vben
authored
|
81
|
return vitePlugins;
|
vben
authored
|
82
|
}
|