From 420d49fe5ec6d4189e33e4bad3e9a5b5f6ad3f3f Mon Sep 17 00:00:00 2001 From: Gimmy <975402925@qq.com> Date: Mon, 2 Sep 2024 11:47:10 +0800 Subject: [PATCH] build(sites): optimize build chunks num --- examples/sites/package.json | 1 + examples/sites/vite.config.ts | 33 +++++++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/examples/sites/package.json b/examples/sites/package.json index 40b5809e2c..d25060042e 100644 --- a/examples/sites/package.json +++ b/examples/sites/package.json @@ -58,6 +58,7 @@ "@vue/compiler-sfc": "^3.2.37", "chalk": "4.1.2", "cross-spawn": "^7.0.3", + "fast-glob": "^3.2.12", "fs-extra": "^10.1.0", "less": "^4.1.3", "markdown-it": "^13.0.1", diff --git a/examples/sites/vite.config.ts b/examples/sites/vite.config.ts index 5b04ab836f..42d610b5df 100644 --- a/examples/sites/vite.config.ts +++ b/examples/sites/vite.config.ts @@ -13,6 +13,30 @@ import vue3SvgPlugin from 'vite-svg-loader' import { getAlias, pathFromWorkspaceRoot, getOptimizeDeps } from '../../internals/cli/src/config/vite' import virtualTemplatePlugin from '@opentiny-internal/unplugin-virtual-template/vite' import tailwindCss from 'tailwindcss' +import fg from 'fast-glob' +import fs from 'fs-extra' + +const delStatic = () => { + let config + return { + name: 'inline-plugin-del-static', + apply: 'build', + configResolved(_config) { + config = _config + }, + async closeBundle() { + const targetPath = path.join(config.build.outDir, '@demos') + const files = await fg(['**/*.spec.js', '**/*.spec.ts'], { + dot: true, + cwd: targetPath + }) + files.forEach((filename) => { + const filePath = path.join(targetPath, filename) + fs.unlink(filePath) + }) + } + } +} export default defineConfig((config) => { const env = loadEnv(config.mode, process.cwd() + '/env', '') @@ -23,17 +47,17 @@ export default defineConfig((config) => { const menuPath = isSaas ? path.resolve('./demos/saas') : path.resolve(demosPath) const copyTarget = [ { - src: `${demosPath}/**`, + src: `${demosPath}/*`, dest: '@demos' }, { - src: `${apisPath}/**`, + src: `${apisPath}/*`, dest: '@demos/apis' } ] if (isSaas) { copyTarget.push({ - src: `./demos/mobile-first/**`, + src: `./demos/mobile-first/*`, dest: '@demos/mobile-first' }) } @@ -75,7 +99,8 @@ export default defineConfig((config) => { Unocss(UnoCssConfig), viteStaticCopy({ targets: copyTarget - }) + }), + delStatic() ], optimizeDeps: getOptimizeDeps(3), build: {