From 9a25822e77f00db3c6ed02f71d222aad2233dff0 Mon Sep 17 00:00:00 2001 From: hwj Date: Mon, 13 Jul 2026 11:47:19 +0800 Subject: [PATCH] =?UTF-8?q?build=EF=BC=9A=E6=9E=84=E5=BB=BA=E9=80=9F?= =?UTF-8?q?=E5=BA=A6=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/vite/index.ts | 20 ++++++++++++++------ vite.config.ts | 20 ++++++++++++-------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/build/vite/index.ts b/build/vite/index.ts index 585759f5..7f7e483c 100644 --- a/build/vite/index.ts +++ b/build/vite/index.ts @@ -16,7 +16,7 @@ import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite' import { createSvgIconsPlugin } from 'vite-plugin-svg-icons' import UnoCSS from 'unocss/vite' -export function createVitePlugins() { +export function createVitePlugins(isBuild = false) { const root = process.cwd() // 路径查找 @@ -24,7 +24,7 @@ export function createVitePlugins() { return resolve(root, '.', dir) } - return [ + const plugins = [ Vue(), VueJsx(), UnoCSS(), @@ -66,10 +66,6 @@ export function createVitePlugins() { resolvers: [ElementPlusResolver()], globs: ["src/components/**/**.{vue, md}", '!src/components/DiyEditor/components/mobile/**'] }), - EslintPlugin({ - cache: false, - include: ['src/**/*.vue', 'src/**/*.ts', 'src/**/*.tsx'] // 检查的文件 - }), VueI18nPlugin({ runtimeOnly: true, compositionOnly: true, @@ -97,4 +93,16 @@ export function createVitePlugins() { promiseImportName: (i) => `__tla_${i}` }) ] + + // ESLint 校验仅在开发环境启用,打包时跳过以提升构建速度(lint 应在开发/提交阶段单独执行) + if (!isBuild) { + plugins.push( + EslintPlugin({ + cache: true, + include: ['src/**/*.vue', 'src/**/*.ts', 'src/**/*.tsx'] // 检查的文件 + }) + ) + } + + return plugins } diff --git a/vite.config.ts b/vite.config.ts index 66ddb9e5..092c8145 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -20,6 +20,12 @@ export default ({command, mode}: ConfigEnv): UserConfig => { } else { env = loadEnv(mode, root) } + + // 打包时需要移除的语句(drop_console / drop_debugger) + const esbuildDrop: ('console' | 'debugger')[] = [] + if (env.VITE_DROP_CONSOLE === 'true') esbuildDrop.push('console') + if (env.VITE_DROP_DEBUGGER === 'true') esbuildDrop.push('debugger') + return { base: env.VITE_BASE_PATH, root: root, @@ -39,7 +45,7 @@ export default ({command, mode}: ConfigEnv): UserConfig => { }, }, // 项目使用的vite插件。 单独提取到build/vite/plugin中管理 - plugins: createVitePlugins(), + plugins: createVitePlugins(isBuild), css: { preprocessorOptions: { scss: { @@ -62,17 +68,15 @@ export default ({command, mode}: ConfigEnv): UserConfig => { } ] }, + // 使用 esbuild 压缩,速度远快于 terser;drop 用于移除 console / debugger + esbuild: { + drop: esbuildDrop + }, build: { - minify: 'terser', + minify: 'esbuild', outDir: env.VITE_OUT_DIR || 'dist', sourcemap: env.VITE_SOURCEMAP === 'true' ? 'inline' : false, // brotliSize: false, - terserOptions: { - compress: { - drop_debugger: env.VITE_DROP_DEBUGGER === 'true', - drop_console: env.VITE_DROP_CONSOLE === 'true' - } - }, rollupOptions: { output: { manualChunks: {