From ea1480dd7c25fb2c331f1fdb7527df24d8553421 Mon Sep 17 00:00:00 2001 From: bighuixiang <472705331@qq.com> Date: Sun, 22 Jun 2025 15:56:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0ESLint=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=B9=B6=E4=BC=98=E5=8C=96Vite=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + package.json | 2 +- vite.config.js | 45 +++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index bf373419..118a6b88 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ dist.rar *.njsproj *.sln *.sw? +.eslintrc-auto-import.json diff --git a/package.json b/package.json index 7077a840..63b09be9 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "dev": "vite", "serve": "vite", "build": "vite build", - "preview": "vite preview", + "preview": "vite preview --port 8080 --host 0.0.0.0", "serve:test": "vite --mode test", "build:test": "vite build --mode test_build", "serve:dev": "vite --mode dev", diff --git a/vite.config.js b/vite.config.js index 1b24aca8..da95a967 100644 --- a/vite.config.js +++ b/vite.config.js @@ -50,12 +50,18 @@ export default defineConfig(({ mode }) => { }, ], dts: "src/auto-imports.d.ts", + // 添加 ESLint 支持 + eslintrc: { + enabled: true, + filepath: "./.eslintrc-auto-import.json", + }, }), createSvgIconsPlugin({ // 指定需要缓存的图标文件夹 iconDirs: [path.resolve(process.cwd(), "src/assets/icons")], // 指定symbolId格式 symbolId: "icon-[dir]-[name]", + inject: "body-last", // 注入位置优化 }), ], css: { @@ -78,6 +84,9 @@ export default defineConfig(({ mode }) => { port: mode === "production" ? 8060 : 10086, // 根据环境设置端口 open: true, // 自动打开浏览器 strictPort: false, // 如果端口已被占用,则尝试下一个可用端口 + hmr: { + overlay: true, + }, proxy: { "/api": { target: "http://192.168.1.7:5567", @@ -100,17 +109,49 @@ export default defineConfig(({ mode }) => { sourcemap: false, // 对应vue.config.js中的productionSourceMap: false outDir: "dist", assetsDir: "assets", - // 分包策略 + target: "es2015", // 目标浏览器版本 + minify: "terser", // 使用terser进行压缩 + cssCodeSplit: true, + // reportCompressedSize: false, // 提升构建速度 + terserOptions: { + compress: { + drop_console: true, // 删除console + drop_debugger: true, // 删除debugger + }, + format: { + comments: false, // 删除注释 + }, + }, + // 优化分包策略 rollupOptions: { output: { manualChunks: { - vendor: ["vue", "vue-router", "vuex"], + vendor: ["vue", "vue-router"], antd: ["ant-design-vue"], + elementPlus: ["element-plus"], utils: ["axios", "lodash-es"], + // 添加更细粒度的分包 + icons: ["@ant-design/icons-vue"], }, + // 优化文件命名 + chunkFileNames: "js/[name]-[hash].js", + entryFileNames: "js/[name]-[hash].js", + assetFileNames: "[ext]/[name]-[hash].[ext]", }, }, }, + // 优化依赖预构建 + optimizeDeps: { + include: [ + "vue", + "vue-router", + "ant-design-vue", + "element-plus", + "axios", + "lodash-es", + ], + exclude: ["@iconify/json"], // 排除大型JSON文件 + }, // 定义全局常量替换 define: { __VUE_OPTIONS_API__: true,