2020-10-27 21:21:14 +08:00
|
|
|
import type { Plugin as VitePlugin } from 'vite';
|
|
|
|
import type { Plugin as rollupPlugin } from 'rollup';
|
|
|
|
|
|
|
|
import PurgeIcons from 'vite-plugin-purge-icons';
|
|
|
|
|
|
|
|
import visualizer from 'rollup-plugin-visualizer';
|
|
|
|
import gzipPlugin from './gzip/index';
|
|
|
|
|
2020-10-28 01:59:37 +08:00
|
|
|
// @ts-ignore
|
|
|
|
import pkg from '../../../package.json';
|
2020-12-22 22:13:03 +08:00
|
|
|
import { isSiteMode, ViteEnv, isReportMode, isBuildGzip } from '../../utils';
|
2020-12-13 21:17:37 +08:00
|
|
|
import { setupHtmlPlugin } from './html';
|
|
|
|
import { setupPwaPlugin } from './pwa';
|
|
|
|
import { setupMockPlugin } from './mock';
|
2020-10-27 21:21:14 +08:00
|
|
|
|
|
|
|
// gen vite plugins
|
2020-12-22 22:13:03 +08:00
|
|
|
export function createVitePlugins(viteEnv: ViteEnv, mode: 'development' | 'production') {
|
2020-10-27 21:21:14 +08:00
|
|
|
const vitePlugins: VitePlugin[] = [];
|
|
|
|
|
|
|
|
// vite-plugin-html
|
2020-12-22 22:13:03 +08:00
|
|
|
setupHtmlPlugin(vitePlugins, viteEnv, mode);
|
2020-12-13 21:17:37 +08:00
|
|
|
// vite-plugin-pwa
|
2020-12-22 22:13:03 +08:00
|
|
|
setupPwaPlugin(vitePlugins, viteEnv, mode);
|
2020-12-13 21:17:37 +08:00
|
|
|
// vite-plugin-mock
|
2020-12-22 22:13:03 +08:00
|
|
|
setupMockPlugin(vitePlugins, viteEnv, mode);
|
2020-10-27 21:21:14 +08:00
|
|
|
|
|
|
|
// vite-plugin-purge-icons
|
|
|
|
vitePlugins.push(PurgeIcons());
|
|
|
|
|
|
|
|
return vitePlugins;
|
|
|
|
}
|
|
|
|
|
|
|
|
// gen rollup plugins
|
|
|
|
export function createRollupPlugin() {
|
|
|
|
const rollupPlugins: rollupPlugin[] = [];
|
|
|
|
|
2020-12-22 22:13:03 +08:00
|
|
|
if (isReportMode()) {
|
2020-12-13 21:17:37 +08:00
|
|
|
// rollup-plugin-visualizer
|
|
|
|
rollupPlugins.push(visualizer({ filename: './build/.cache/stats.html', open: true }) as Plugin);
|
2020-10-27 21:21:14 +08:00
|
|
|
}
|
2020-12-22 22:13:03 +08:00
|
|
|
if (isBuildGzip() || isSiteMode()) {
|
2020-12-13 21:17:37 +08:00
|
|
|
// rollup-plugin-gizp
|
|
|
|
rollupPlugins.push(gzipPlugin());
|
|
|
|
}
|
|
|
|
|
2020-10-27 21:21:14 +08:00
|
|
|
return rollupPlugins;
|
|
|
|
}
|