2025-04-29 23:21:40 +08:00
|
|
|
|
import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite';
|
|
|
|
|
import tailwindcss from '@tailwindcss/vite';
|
|
|
|
|
import vue from '@vitejs/plugin-vue';
|
|
|
|
|
import vueJsx from '@vitejs/plugin-vue-jsx';
|
|
|
|
|
import { codeInspectorPlugin } from 'code-inspector-plugin';
|
|
|
|
|
import { visualizer } from 'rollup-plugin-visualizer';
|
|
|
|
|
import Icons from 'unplugin-icons/vite';
|
|
|
|
|
import type { PluginOption } from 'vite';
|
|
|
|
|
import removeConsole from 'vite-plugin-remove-console';
|
|
|
|
|
import removeNoMatch from 'vite-plugin-router-warn';
|
|
|
|
|
import svgLoader from 'vite-svg-loader';
|
|
|
|
|
import { cdn } from './cdn';
|
|
|
|
|
import { configCompressPlugin } from './compress';
|
|
|
|
|
import { viteBuildInfo } from './info';
|
2024-09-26 09:38:02 +08:00
|
|
|
|
|
2025-04-29 23:21:40 +08:00
|
|
|
|
export function getPluginsList(VITE_CDN: boolean, VITE_COMPRESSION: ViteCompression, VITE_PORT: number): PluginOption[] {
|
2025-04-25 16:21:15 +08:00
|
|
|
|
const lifecycle = process.env.npm_lifecycle_event;
|
|
|
|
|
return [
|
2025-04-29 18:18:07 +08:00
|
|
|
|
tailwindcss(),
|
|
|
|
|
vue({
|
|
|
|
|
template: {
|
|
|
|
|
compilerOptions: {
|
2025-04-29 23:21:40 +08:00
|
|
|
|
isCustomElement: (tag) => tag === 'deep-chat',
|
|
|
|
|
},
|
|
|
|
|
},
|
2025-04-29 18:18:07 +08:00
|
|
|
|
}),
|
2025-04-25 16:21:15 +08:00
|
|
|
|
// jsx、tsx语法支持
|
|
|
|
|
vueJsx(),
|
|
|
|
|
VueI18nPlugin({
|
2025-04-29 18:18:07 +08:00
|
|
|
|
// include: [pathResolve("../locales/**")]
|
2025-04-25 16:21:15 +08:00
|
|
|
|
}),
|
2025-04-29 18:18:07 +08:00
|
|
|
|
/**
|
|
|
|
|
* 在页面上按住组合键时,鼠标在页面移动即会在 DOM 上出现遮罩层并显示相关信息,点击一下将自动打开 IDE 并将光标定位到元素对应的代码位置
|
|
|
|
|
* Mac 默认组合键 Option + Shift
|
|
|
|
|
* Windows 默认组合键 Alt + Shift
|
|
|
|
|
* 更多用法看 https://inspector.fe-dev.cn/guide/start.html
|
|
|
|
|
*/
|
|
|
|
|
codeInspectorPlugin({
|
2025-04-29 23:21:40 +08:00
|
|
|
|
bundler: 'vite',
|
|
|
|
|
hideConsole: true,
|
2025-04-29 18:18:07 +08:00
|
|
|
|
}),
|
2025-04-29 23:21:40 +08:00
|
|
|
|
viteBuildInfo(VITE_PORT),
|
2025-04-25 16:21:15 +08:00
|
|
|
|
/**
|
|
|
|
|
* 开发环境下移除非必要的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(),
|
2025-04-29 18:18:07 +08:00
|
|
|
|
// mock支持
|
2025-04-25 16:21:15 +08:00
|
|
|
|
// vitePluginFakeServer({
|
2025-04-29 18:18:07 +08:00
|
|
|
|
// logger: false,
|
|
|
|
|
// include: "mock",
|
|
|
|
|
// infixName: false,
|
|
|
|
|
// enableProd: true
|
2025-04-25 16:21:15 +08:00
|
|
|
|
// }),
|
|
|
|
|
// svg组件化支持
|
|
|
|
|
svgLoader(),
|
2025-04-29 18:18:07 +08:00
|
|
|
|
// 自动按需加载图标
|
|
|
|
|
Icons({
|
2025-04-29 23:21:40 +08:00
|
|
|
|
compiler: 'vue3',
|
|
|
|
|
scale: 1,
|
2025-04-29 18:18:07 +08:00
|
|
|
|
}),
|
2025-04-25 16:21:15 +08:00
|
|
|
|
VITE_CDN ? cdn : null,
|
|
|
|
|
configCompressPlugin(VITE_COMPRESSION),
|
|
|
|
|
// 线上环境删除console
|
2025-04-29 23:21:40 +08:00
|
|
|
|
removeConsole({ external: ['src/assets/iconfont/iconfont.js'] }),
|
2025-04-25 16:21:15 +08:00
|
|
|
|
// 打包分析
|
2025-04-29 23:21:40 +08:00
|
|
|
|
lifecycle === 'report' ? visualizer({ open: true, brotliSize: true, filename: 'report.html' }) : (null as any),
|
2025-04-25 16:21:15 +08:00
|
|
|
|
];
|
2024-09-26 09:38:02 +08:00
|
|
|
|
}
|