2024-09-04 14:59:06 +08:00
|
|
|
|
import { cdn } from './cdn';
|
|
|
|
|
import vue from '@vitejs/plugin-vue';
|
|
|
|
|
import { viteBuildInfo } from './info';
|
|
|
|
|
import svgLoader from 'vite-svg-loader';
|
|
|
|
|
import type { PluginOption } from 'vite';
|
|
|
|
|
import vueJsx from '@vitejs/plugin-vue-jsx';
|
|
|
|
|
import Inspector from 'vite-plugin-vue-inspector';
|
|
|
|
|
import { configCompressPlugin } from './compress';
|
|
|
|
|
import removeNoMatch from 'vite-plugin-router-warn';
|
|
|
|
|
import { visualizer } from 'rollup-plugin-visualizer';
|
|
|
|
|
import removeConsole from 'vite-plugin-remove-console';
|
|
|
|
|
import { themePreprocessorPlugin } from '@pureadmin/theme';
|
|
|
|
|
import { genScssMultipleScopeVars } from '../src/layout/theme';
|
|
|
|
|
import { vitePluginFakeServer } from 'vite-plugin-fake-server';
|
2024-09-03 13:18:58 +08:00
|
|
|
|
|
2024-09-04 14:59:06 +08:00
|
|
|
|
export function getPluginsList(VITE_CDN: boolean, VITE_COMPRESSION: ViteCompression, VITE_PORT: number): PluginOption[] {
|
|
|
|
|
const lifecycle = process.env.npm_lifecycle_event;
|
|
|
|
|
return [
|
|
|
|
|
vue(),
|
|
|
|
|
// jsx、tsx语法支持
|
|
|
|
|
vueJsx(),
|
|
|
|
|
// 按下Command(⌘)+Shift(⇧),然后点击页面元素会自动打开本地IDE并跳转到对应的代码位置
|
|
|
|
|
Inspector(),
|
|
|
|
|
viteBuildInfo(VITE_PORT),
|
|
|
|
|
/**
|
|
|
|
|
* 开发环境下移除非必要的vue-router动态路由警告No match found for location with path
|
|
|
|
|
* 非必要具体看 https://github.com/vuejs/router/issues/521 和 https://github.com/vuejs/router/issues/359
|
|
|
|
|
* vite-plugin-router-warn只在开发环境下启用,只处理vue-router文件并且只在服务启动或重启时运行一次,性能消耗可忽略不计
|
|
|
|
|
*/
|
|
|
|
|
removeNoMatch(),
|
|
|
|
|
// mock支持
|
|
|
|
|
vitePluginFakeServer({
|
|
|
|
|
logger: false,
|
|
|
|
|
include: 'mock',
|
|
|
|
|
infixName: false,
|
|
|
|
|
enableProd: true,
|
|
|
|
|
}),
|
|
|
|
|
// 自定义主题
|
|
|
|
|
themePreprocessorPlugin({
|
|
|
|
|
scss: {
|
|
|
|
|
multipleScopeVars: genScssMultipleScopeVars(),
|
|
|
|
|
extract: true,
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
// svg组件化支持
|
|
|
|
|
svgLoader(),
|
|
|
|
|
VITE_CDN ? cdn : null,
|
|
|
|
|
configCompressPlugin(VITE_COMPRESSION),
|
|
|
|
|
// 线上环境删除console
|
|
|
|
|
removeConsole({ external: ['src/assets/iconfont/iconfont.js'] }),
|
|
|
|
|
// 打包分析
|
|
|
|
|
lifecycle === 'report' ? visualizer({ open: true, brotliSize: true, filename: 'report.html' }) : (null as any),
|
|
|
|
|
];
|
2024-09-03 13:18:58 +08:00
|
|
|
|
}
|