From 5cb92b328ec7cff6aa619ab49da078e0cd3c96e7 Mon Sep 17 00:00:00 2001 From: Alex <49969959+alexzhang1030@users.noreply.github.com> Date: Mon, 18 Dec 2023 21:27:44 +0800 Subject: [PATCH] build: cleanup bundle dir before building (#86) Co-authored-by: Arlo --- packages/client/vite.config.ts | 22 ++++++++++------------ packages/client/vite.lib.config.ts | 14 ++++++-------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/packages/client/vite.config.ts b/packages/client/vite.config.ts index 80870459..91a69f5f 100644 --- a/packages/client/vite.config.ts +++ b/packages/client/vite.config.ts @@ -13,18 +13,16 @@ export default defineConfig(mergeConfig(baseConfig, { closeBundle() { // copy const clientFile = resolve(__dirname, './dist') - fse.copySync( - clientFile, - resolve(__dirname, '../browser-extension/client'), - ) - fse.copySync( - clientFile, - resolve(__dirname, '../electron/client'), - ) - fse.copySync( - clientFile, - resolve(__dirname, '../vite/dist/client'), - ) + + // Removed `browser-extension` and `electron` on `build:lib` + // Remove `vite/dist/client` on building + ;['../vite/dist/client'].forEach((dir) => { + fse.rmSync(resolve(__dirname, dir), { recursive: true, force: true }) + }) + + ;['../browser-extension/client', '../electron/client', '../vite/dist/client'].forEach((dir) => { + fse.copySync(clientFile, resolve(__dirname, dir)) + }) }, }, ], diff --git a/packages/client/vite.lib.config.ts b/packages/client/vite.lib.config.ts index 8d532caf..4414ebbb 100644 --- a/packages/client/vite.lib.config.ts +++ b/packages/client/vite.lib.config.ts @@ -42,14 +42,12 @@ export default defineConfig(mergeConfig(baseConfig, { closeBundle() { // copy const clientFile = resolve(__dirname, './dist') - fse.copySync( - clientFile, - resolve(__dirname, '../browser-extension/client'), - ) - fse.copySync( - clientFile, - resolve(__dirname, '../electron/client'), - ) + ;['../browser-extension/client', '../electron/client'].forEach((dir) => { + // NOTE: remember the order of `build:lib` and `build`, + // if change the order, rmSync must set in `build` stage + fse.rmSync(resolve(__dirname, dir), { recursive: true, force: true }) + fse.copySync(clientFile, resolve(__dirname, dir)) + }) }, }, ],