From 71c1f24a8ad3c35ca9ccfb11a4e7b6e29cc51e60 Mon Sep 17 00:00:00 2001 From: wangdan Date: Tue, 25 Apr 2023 17:30:09 +0800 Subject: [PATCH] feat: --- README.md | 37 ++++++++++++++++++--- stats.html | 2 +- vite.config.ts | 89 +++++++++++++++++++++++++------------------------- 3 files changed, 78 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index e1713c3..a885e51 100644 --- a/README.md +++ b/README.md @@ -115,6 +115,39 @@ rollupOptions: { ![image](src/assets/readme/4.png) +也可以分不同的文件夹,打包之后每个模块一个文件夹 + +``` + build: { + rollupOptions: { + output: { + // 用于命名代码拆分时创建的共享块的输出命名 + chunkFileNames: (chunkInfo) => { + const facadeModuleId = chunkInfo.facadeModuleId + ? chunkInfo.facadeModuleId.split('/') + : []; + const fileName = + facadeModuleId[facadeModuleId.length - 2] || '[name]'; + return `js/${fileName}/[name].[hash].js`; + }, + // 用于从入口点创建的块的打包输出格式 + entryFileNames: `js/[name]-[hash].js`, + // assetFileNames 不设置 所有css和图片文件就默认在assets中 + // assetFileNames: `assets/[ext]/[name]-[hash].[ext]`, + manualChunks(id: string) { + if (id.includes('node_modules')) { + return 'vendor' + } + // 一个模块只要一个文件,如果需要一个vue一个文件,以下代码可忽略 + if (id.includes('/src/views/')) { + return id.toString().split('/src/views/')[1].split('/')[0] + } + } + } + } + } +``` + ### 3、第三方代码分包后,文件过于琐碎,只单独提出个别大文件 @@ -144,10 +177,6 @@ rollupOptions: { if (id.includes('node_modules')) { if (id.includes('vue')) { return 'vue' - } else if (id.includes('element-plus')) { - return 'element-plus' - } else if (id.includes('fit2cloud-ui-plus')) { - return 'fit2cloud-ui-plus' } else if (id.includes('axios')) { return 'axios' } diff --git a/stats.html b/stats.html index 7f5f193..f1bf43b 100644 --- a/stats.html +++ b/stats.html @@ -6157,7 +6157,7 @@