fix(vite): 升级开发依赖并禁用 glob 转换

This commit is contained in:
zhanjunhao
2026-11-23 16:07:24 +08:00
parent b0454bb1ee
commit 440540bd19
5 changed files with 267 additions and 135 deletions
+25 -2
View File
@@ -38,6 +38,28 @@ function jsxInJsPlugin() {
};
}
function disableDevImportGlob() {
return {
name: 'disable-dev-import-glob',
apply: 'serve',
configResolved(config) {
if (config.isPreview) return;
const plugin = config.plugins.find(
({ name }) => name === 'vite:import-glob',
);
if (!plugin)
throw new Error('Unable to disable the Vite import glob transform');
// Guard the built-in hook itself, including source generated by other plugins.
plugin.transform = function (code) {
if (code.includes('import.meta.glob')) {
this.error('import.meta.glob is disabled in the development server');
}
};
},
};
}
/**
* 向 index.html 注入统计脚本。
*
@@ -102,6 +124,7 @@ export default defineConfig(({ mode, command }) => {
},
},
plugins: [
disableDevImportGlob(),
jsxInJsPlugin(),
react(),
analyticsPlugin(env),
@@ -147,9 +170,9 @@ export default defineConfig(({ mode, command }) => {
},
},
server: {
// 监听所有网卡,便于局域网与容器内访问
// 监听局域网接口,供本机、后端及测试人员联调。
host: '0.0.0.0',
port: '5174',
port: 5174,
warmup: {
clientFiles: [
'./src/index.jsx',