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
|
// @vitejs/plugin-legacy
|
vben
authored
|
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
VITE_LEGACY &&
isBuild &&
vitePlugins.push(
legacy({
targets: [
'Android > 39',
'Chrome >= 60',
'Safari >= 10.1',
'iOS >= 10.3',
'Firefox >= 54',
'Edge >= 15',
],
additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
})
);
|
vben
authored
|
55
56
|
// vite-plugin-html
|
vben
authored
|
57
58
|
vitePlugins.push(configHtmlPlugin(viteEnv, isBuild));
|
Vben
authored
|
59
60
61
|
// vite-plugin-svg-icons
vitePlugins.push(configSvgIconsPlugin(isBuild));
|
vben
authored
|
62
|
// vite-plugin-mock
|
vben
authored
|
63
|
VITE_USE_MOCK && vitePlugins.push(configMockPlugin(isBuild));
|
vben
authored
|
64
|
|
vben
authored
|
65
|
// vite-plugin-purge-icons
|
vben
authored
|
66
|
vitePlugins.push(purgeIcons());
|
vben
authored
|
67
|
|
vben
authored
|
68
|
// vite-plugin-style-import
|
Vben
authored
|
69
|
vitePlugins.push(configStyleImportPlugin(isBuild));
|
vben
authored
|
70
|
|
vben
authored
|
71
|
// rollup-plugin-visualizer
|
vben
authored
|
72
|
vitePlugins.push(configVisualizerConfig());
|
vben
authored
|
73
|
|
vben
authored
|
74
|
//vite-plugin-theme
|
Vben
authored
|
75
|
vitePlugins.push(configThemePlugin(isBuild));
|
vben
authored
|
76
|
|
vben
authored
|
77
|
// The following plugins only work in the production environment
|
vben
authored
|
78
79
|
if (isBuild) {
//vite-plugin-imagemin
|
vben
authored
|
80
|
VITE_USE_IMAGEMIN && vitePlugins.push(configImageminPlugin());
|
vben
authored
|
81
82
|
// rollup-plugin-gzip
|
|
83
84
85
|
vitePlugins.push(
configCompressPlugin(VITE_BUILD_COMPRESS, VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE)
);
|
vben
authored
|
86
87
88
89
90
|
// vite-plugin-pwa
vitePlugins.push(configPwaConfig(viteEnv));
}
|
vben
authored
|
91
|
return vitePlugins;
|
vben
authored
|
92
|
}
|