Skip to content

Commit abc23cc

Browse files
author
sunshine824
committed
拆分打包文件
1 parent 25c3195 commit abc23cc

File tree

4 files changed

+77
-6
lines changed

4 files changed

+77
-6
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"prettier": "^2.3.1",
3333
"typescript": "^4.3.2",
3434
"vite": "^2.3.7",
35+
"vite-plugin-compression": "^0.4.0",
3536
"vite-plugin-style-import": "^1.0.1",
3637
"vue-tsc": "^0.0.24"
3738
}

src/router/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function fnAddDynamicMenuRoutes(
3030
routes.push({
3131
path: `${item.url}`,
3232
name: item.name.slice(0, 1) == '/' ? item.name.slice(1) : item.name, // 截取开头"/"
33-
component: () => import('../views' + item.url + '/index'),
33+
component: () => import(`../views${item.url}/index`),
3434
meta: {
3535
title: item.title,
3636
hidden: false,

vite.config.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import vue from '@vitejs/plugin-vue'
33
import path from 'path'
44
import vueJsx from '@vitejs/plugin-vue-jsx'
55
import styleImport from 'vite-plugin-style-import'
6-
7-
import { resolve } from 'path'
6+
import viteCompression from 'vite-plugin-compression'
87

98
// https://vitejs.dev/config/
109
export default defineConfig({
@@ -23,13 +22,30 @@ export default defineConfig({
2322
jsxInject: "import { h } from 'vue';",
2423
},
2524
build: {
26-
// 去除console
25+
chunkSizeWarningLimit: 500,
26+
minify: 'terser',
27+
cssCodeSplit: true, // 如果设置为false,整个项目中的所有 CSS 将被提取到一个 CSS 文件中
2728
terserOptions: {
2829
compress: {
29-
drop_console: true,
30-
drop_debugger: true,
30+
drop_console: true, //打包时删除console
31+
drop_debugger: true, //打包时删除 debugger
32+
pure_funcs: ['console.log'],
33+
},
34+
output: {
35+
// 去掉注释内容
36+
comments: true,
37+
},
38+
},
39+
rollupOptions: {
40+
output: {
41+
manualChunks: {
42+
// 拆分代码,这个就是分包,配置完后自动按需加载,现在还比不上webpack的splitchunk,不过也能用了。
43+
vue: ['vue', 'vue-router', 'vuex'],
44+
'ant-design-vue': ['ant-design-vue'],
45+
},
3146
},
3247
},
48+
brotliSize: false,
3349
},
3450
plugins: [
3551
vue(),
@@ -45,6 +61,8 @@ export default defineConfig({
4561
},
4662
],
4763
}),
64+
// 打包压缩,主要是本地gzip,如果服务器配置压缩也可以
65+
viteCompression(),
4866
],
4967
css: {
5068
preprocessorOptions: {

yarn.lock

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,14 @@ chalk@^4.0.0:
764764
ansi-styles "^4.1.0"
765765
supports-color "^7.1.0"
766766

767+
chalk@^4.1.2:
768+
version "4.1.2"
769+
resolved "https://registry.npmmirror.com/chalk/download/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01"
770+
integrity sha1-qsTit3NKdAhnrrFr8CqtVWoeegE=
771+
dependencies:
772+
ansi-styles "^4.1.0"
773+
supports-color "^7.1.0"
774+
767775
change-case@^4.1.2:
768776
version "4.1.2"
769777
resolved "https://registry.npm.taobao.org/change-case/download/change-case-4.1.2.tgz?cache=0&sync_timestamp=1606867703975&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fchange-case%2Fdownload%2Fchange-case-4.1.2.tgz#fedfc5f136045e2398c0410ee441f95704641e12"
@@ -916,6 +924,13 @@ debug@^4.3.2:
916924
dependencies:
917925
ms "2.1.2"
918926

927+
debug@^4.3.3:
928+
version "4.3.3"
929+
resolved "https://registry.npmmirror.com/debug/download/debug-4.3.3.tgz#04266e0b70a98d4462e6e288e38259213332b664"
930+
integrity sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q==
931+
dependencies:
932+
ms "2.1.2"
933+
919934
deep-is@^0.1.3:
920935
version "0.1.3"
921936
resolved "https://registry.npm.taobao.org/deep-is/download/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34"
@@ -1234,6 +1249,15 @@ follow-redirects@^1.10.0:
12341249
resolved "https://registry.nlark.com/follow-redirects/download/follow-redirects-1.14.2.tgz#cecb825047c00f5e66b142f90fed4f515dec789b"
12351250
integrity sha1-zsuCUEfAD15msUL5D+1PUV3seJs=
12361251

1252+
fs-extra@^10.0.0:
1253+
version "10.0.0"
1254+
resolved "https://registry.nlark.com/fs-extra/download/fs-extra-10.0.0.tgz#9ff61b655dde53fb34a82df84bb214ce802e17c1"
1255+
integrity sha1-n/YbZV3eU/s0qC34S7IUzoAuF8E=
1256+
dependencies:
1257+
graceful-fs "^4.2.0"
1258+
jsonfile "^6.0.1"
1259+
universalify "^2.0.0"
1260+
12371261
fs.realpath@^1.0.0:
12381262
version "1.0.0"
12391263
resolved "https://registry.npm.taobao.org/fs.realpath/download/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
@@ -1333,6 +1357,11 @@ graceful-fs@^4.1.2, graceful-fs@^4.2.2:
13331357
resolved "https://registry.npm.taobao.org/graceful-fs/download/graceful-fs-4.2.6.tgz#ff040b2b0853b23c3d31027523706f1885d76bee"
13341358
integrity sha1-/wQLKwhTsjw9MQJ1I3BvGIXXa+4=
13351359

1360+
graceful-fs@^4.1.6, graceful-fs@^4.2.0:
1361+
version "4.2.8"
1362+
resolved "https://registry.npmmirror.com/graceful-fs/download/graceful-fs-4.2.8.tgz#e412b8d33f5e006593cbd3cee6df9f2cebbe802a"
1363+
integrity sha1-5BK40z9eAGWTy9PO5t+fLOu+gCo=
1364+
13361365
has-flag@^3.0.0:
13371366
version "3.0.0"
13381367
resolved "https://registry.npm.taobao.org/has-flag/download/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd"
@@ -1527,6 +1556,15 @@ json5@^2.1.2:
15271556
dependencies:
15281557
minimist "^1.2.5"
15291558

1559+
jsonfile@^6.0.1:
1560+
version "6.1.0"
1561+
resolved "https://registry.nlark.com/jsonfile/download/jsonfile-6.1.0.tgz#bc55b2634793c679ec6403094eb13698a6ec0aae"
1562+
integrity sha1-vFWyY0eTxnnsZAMJTrE2mKbsCq4=
1563+
dependencies:
1564+
universalify "^2.0.0"
1565+
optionalDependencies:
1566+
graceful-fs "^4.1.6"
1567+
15301568
klona@^2.0.4:
15311569
version "2.0.4"
15321570
resolved "https://registry.npm.taobao.org/klona/download/klona-2.0.4.tgz#7bb1e3affb0cb8624547ef7e8f6708ea2e39dfc0"
@@ -2287,6 +2325,11 @@ typescript@^4.3.2:
22872325
resolved "https://registry.nlark.com/typescript/download/typescript-4.3.4.tgz?cache=0&sync_timestamp=1624260319959&other_urls=https%3A%2F%2Fregistry.nlark.com%2Ftypescript%2Fdownload%2Ftypescript-4.3.4.tgz#3f85b986945bcf31071decdd96cf8bfa65f9dcbc"
22882326
integrity sha1-P4W5hpRbzzEHHezdls+L+mX53Lw=
22892327

2328+
universalify@^2.0.0:
2329+
version "2.0.0"
2330+
resolved "https://registry.nlark.com/universalify/download/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717"
2331+
integrity sha1-daSYTv7cSwiXXFrrc/Uw0C3yVxc=
2332+
22902333
unzipper@0.10.11:
22912334
version "0.10.11"
22922335
resolved "https://registry.npm.taobao.org/unzipper/download/unzipper-0.10.11.tgz#0b4991446472cbdb92ee7403909f26c2419c782e"
@@ -2334,6 +2377,15 @@ v8-compile-cache@^2.0.3:
23342377
resolved "https://registry.nlark.com/v8-compile-cache/download/v8-compile-cache-2.3.0.tgz#2de19618c66dc247dcfb6f99338035d8245a2cee"
23352378
integrity sha1-LeGWGMZtwkfc+2+ZM4A12CRaLO4=
23362379

2380+
vite-plugin-compression@^0.4.0:
2381+
version "0.4.0"
2382+
resolved "https://registry.npmmirror.com/vite-plugin-compression/download/vite-plugin-compression-0.4.0.tgz#e462924faa797514e6bd05fd2f0e33cd8403817f"
2383+
integrity sha512-CGC8DfIey0k4S4o54ylwFIzT1Mjb9s7cMmlXj6DMM1MZZIeWFjPCJc6YZWjnnS28ul3r7R1nmihvYvGg/lOYsQ==
2384+
dependencies:
2385+
chalk "^4.1.2"
2386+
debug "^4.3.3"
2387+
fs-extra "^10.0.0"
2388+
23372389
vite-plugin-style-import@^1.0.1:
23382390
version "1.0.1"
23392391
resolved "https://registry.nlark.com/vite-plugin-style-import/download/vite-plugin-style-import-1.0.1.tgz#bf61337dd11e4ebc0f355f271e06d374b1ca5c79"

0 commit comments

Comments
 (0)