From b6910031870a940e4b97f65f1c018f8aae02091f Mon Sep 17 00:00:00 2001 From: MTrun <1262327911@qq.com> Date: Tue, 1 Mar 2022 16:46:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=A7=BB=E5=8A=A8=E6=89=93=E5=8C=85?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/constant.ts | 24 ++++++++++++++++++++++++ vite.config.ts | 22 +++++----------------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/build/constant.ts b/build/constant.ts index 20445820..dfa2f491 100644 --- a/build/constant.ts +++ b/build/constant.ts @@ -1 +1,25 @@ export const OUTPUT_DIR = 'dist'; + +// chunk 警告大小 +export const chunkSizeWarningLimit = 2000 + +// 禁用 brotli 压缩大小报告 +export const brotliSize = false + +// 分包 +export const rollupOptions = { + output: { + chunkFileNames: 'static/js/[name]-[hash].js', + entryFileNames: 'static/js/[name]-[hash].js', + assetFileNames: 'static/[ext]/[name]-[hash].[ext]' + } +} + +// 去除开发代码 +export const terserOptions = { + compress: { + keep_infinity: true, + drop_console: true, + drop_debugger: true + } +} \ No newline at end of file diff --git a/vite.config.ts b/vite.config.ts index 7baf65d3..f04f56b2 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,7 +1,7 @@ import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' import { resolve } from 'path' -import { OUTPUT_DIR } from './build/constant' +import { OUTPUT_DIR, brotliSize, chunkSizeWarningLimit, terserOptions, rollupOptions } from './build/constant' import viteCompression from 'vite-plugin-compression' function pathResolve(dir: string) { @@ -44,21 +44,9 @@ export default defineConfig({ build: { target: 'es2015', outDir: OUTPUT_DIR, - terserOptions: { - compress: { - keep_infinity: true, - drop_console: true, - drop_debugger: true - } - }, - rollupOptions: { - output: { - chunkFileNames: 'static/js/[name]-[hash].js', - entryFileNames: 'static/js/[name]-[hash].js', - assetFileNames: 'static/[ext]/[name]-[hash].[ext]' - } - }, - brotliSize: false, - chunkSizeWarningLimit: 2000 + terserOptions: terserOptions, + rollupOptions: rollupOptions, + brotliSize: brotliSize, + chunkSizeWarningLimit: chunkSizeWarningLimit } })