Files
JoyD/AutoRobot/Windows/Robot/Web/vite.config.js
zqm e96e3018ed ### 主要修复内容
1. 事件监听器泄漏 :修复了事件监听器泄漏问题,确保所有监听器都能被正确清理
2. 组件生命周期管理 :为所有组件添加了onUnmounted钩子,确保资源能被正确清理
3. props大小写问题 :修复了props名称大小写不匹配问题
4. 延迟初始化 :将事件管理器的初始化从立即初始化改为延迟初始化,提高性能
5. flexbox布局修复 :修复了flexbox布局问题,确保组件能正确显示
6. 代码结构优化 :简化了代码结构,提高了可维护性
这些修改解决了事件监听器泄漏、组件生命周期管理和props传递等问题,提高了代码的质量和可维护性。
2025-12-04 14:58:41 +08:00

88 lines
2.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
// 定义一个简单的插件来解决阿里云SDK加载问题
const fixAliyunSDKPlugin = {
name: 'fix-aliyun-sdk',
enforce: 'pre',
transform(code, id) {
// 在构建时移除对阿里云安全SDK的引用
// 这个正则会匹配可能的阿里云SDK引入代码
if (code.includes('ice-plugin-spm') || code.includes('APlus') || code.includes('securitySDK')) {
return code
.replace(/import\s+.*ice-plugin-spm.*;/g, '')
.replace(/import\s+.*APlus.*;/g, '')
.replace(/import\s+.*securitySDK.*;/g, '')
.replace(/\s*script\s*src\s*=\s*["']https:\/\/o\.alicdn\.com\/tbpc\/securitySDK\/securitySDK\.umd\.js["']\s*>/g, '')
}
return null;
}
};
export default defineConfig(({ mode }) => {
const isDebug = mode === 'debug'
const isRelease = mode === 'release'
return {
// 配置Vue插件以支持更好的调试体验
plugins: [
vue({
template: {
compilerOptions: {
// 启用调试提示
whitespace: 'preserve'
}
}
}),
fixAliyunSDKPlugin // 添加我们的修复插件
],
server: {
port: 8081, // 改为不同于后端的端口
proxy: {
// 添加代理配置将WebSocket请求转发到后端
'/': {
target: 'http://localhost:8805',
ws: true,
changeOrigin: true,
// 配置代理超时时间,避免过早断开连接
timeout: 60000,
// 配置重写规则
rewrite: (path) => path
}
}
},
// 根据模式配置构建选项
build: {
// 调试模式下启用sourcemap发布模式下禁用
sourcemap: isDebug,
// 调试模式下禁用压缩,发布模式下启用
minify: isRelease,
// 根据模式设置不同的输出目录
outDir: 'dist',
// 配置外部依赖,避免打包不必要的库
rollupOptions: {
external: ['https://o.alicdn.com/tbpc/securitySDK/securitySDK.umd.js']
}
},
// 配置CSS预处理器选项
css: {
preprocessorOptions: {
css: {
// 禁用@import内联可能有助于解决一些导入问题
url: false
},
// 配置Sass使用现代API避免旧版JS API警告
scss: {
api: 'modern-compiler'
},
sass: {
api: 'modern-compiler'
}
}
},
// 配置开发服务器的CSP头信息
headers: {
'Content-Security-Policy': "script-src 'self' 'unsafe-inline' 'unsafe-eval'"
}
}
})