From 4e1069ec1d055cc2ccf97bbdc8237b5dadd752aa Mon Sep 17 00:00:00 2001
From: MTrun <1262327911@qq.com>
Date: Mon, 28 Feb 2022 20:26:41 +0800
Subject: [PATCH] =?UTF-8?q?build:=20=E4=BF=AE=E6=94=B9=E6=89=93=E5=8C=85?=
 =?UTF-8?q?=E9=85=8D=E7=BD=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 vite.config.ts | 45 +++++++++++++++++++++++++++++++--------------
 1 file changed, 31 insertions(+), 14 deletions(-)

diff --git a/vite.config.ts b/vite.config.ts
index 266526cd..7baf65d3 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -1,37 +1,45 @@
 import { defineConfig } from 'vite'
 import vue from '@vitejs/plugin-vue'
-import { resolve } from "path"
+import { resolve } from 'path'
 import { OUTPUT_DIR } from './build/constant'
+import viteCompression from 'vite-plugin-compression'
 
 function pathResolve(dir: string) {
-  return resolve(process.cwd(), '.', dir);
+  return resolve(process.cwd(), '.', dir)
 }
 
 export default defineConfig({
-  base: "./",
+  base: './',
   resolve: {
     alias: [
       {
         find: /\/#\//,
-        replacement: pathResolve('types') + '/',
+        replacement: pathResolve('types') + '/'
       },
       {
         find: '@',
-        replacement: pathResolve('src') + '/',
+        replacement: pathResolve('src') + '/'
       }
     ],
-    dedupe: ['vue'],
+    dedupe: ['vue']
   },
   css: {
     preprocessorOptions: {
       scss: {
         javascriptEnabled: true,
-        additionalData: `@import "src/styles/common/style.scss";`,
-      },
-    },
+        additionalData: `@import "src/styles/common/style.scss";`
+      }
+    }
   },
   plugins: [
-    vue()
+    vue(),
+    viteCompression({
+      verbose: true,
+      disable: false,
+      threshold: 10240,
+      algorithm: 'gzip',
+      ext: '.gz'
+    })
   ],
   build: {
     target: 'es2015',
@@ -39,9 +47,18 @@ export default defineConfig({
     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,
-  },
-})
\ No newline at end of file
+    chunkSizeWarningLimit: 2000
+  }
+})