From 9863b72192bf279b0c4d2af5c16ec6b6378125b9 Mon Sep 17 00:00:00 2001 From: neverland Date: Sun, 22 Dec 2024 20:39:23 +0800 Subject: [PATCH] Revert "fix: should copy publicDir to the environment distDir when multiple environments (#4220)" (#4240) --- e2e/cases/server/public-dir/publicDir.test.ts | 39 ------------------- packages/core/src/plugins/server.ts | 20 +++------- 2 files changed, 6 insertions(+), 53 deletions(-) diff --git a/e2e/cases/server/public-dir/publicDir.test.ts b/e2e/cases/server/public-dir/publicDir.test.ts index c8665186d7..86ec67fe75 100644 --- a/e2e/cases/server/public-dir/publicDir.test.ts +++ b/e2e/cases/server/public-dir/publicDir.test.ts @@ -170,45 +170,6 @@ test('should serve publicDir for preview server correctly', async ({ await rsbuild.close(); }); -test('should copy publicDir to the environment distDir when multiple environments', async () => { - await fse.outputFile(join(__dirname, 'public', 'test-temp-file.txt'), 'a'); - - const rsbuild = await build({ - cwd, - rsbuildConfig: { - environments: { - web1: { - output: { - distPath: { - root: 'dist-build-web-1', - }, - }, - }, - web2: { - output: { - distPath: { - root: 'dist-build-web-2', - }, - }, - }, - }, - }, - }); - const files = await rsbuild.unwrapOutputJSON(); - const filenames = Object.keys(files); - - expect( - filenames.some((filename) => - filename.includes('dist-build-web-1/test-temp-file.txt'), - ), - ).toBeTruthy(); - expect( - filenames.some((filename) => - filename.includes('dist-build-web-2/test-temp-file.txt'), - ), - ).toBeTruthy(); -}); - test('should serve publicDir for preview server with assetPrefix correctly', async ({ page, }) => { diff --git a/packages/core/src/plugins/server.ts b/packages/core/src/plugins/server.ts index dd875a6685..6ef1f784f2 100644 --- a/packages/core/src/plugins/server.ts +++ b/packages/core/src/plugins/server.ts @@ -23,7 +23,7 @@ export const pluginServer = (): RsbuildPlugin => ({ api.onAfterStartDevServer(onStartServer); api.onAfterStartProdServer(onStartServer); - api.onBeforeBuild(async ({ isFirstCompile, environments }) => { + api.onBeforeBuild(async ({ isFirstCompile }) => { if (!isFirstCompile) { return; } @@ -45,22 +45,14 @@ export const pluginServer = (): RsbuildPlugin => ({ continue; } - const distPaths = [ - ...new Set(Object.values(environments).map((e) => e.distPath)), - ]; - try { // async errors will missing error stack on copy, move // https://github.com/jprichardson/node-fs-extra/issues/769 - await Promise.all( - distPaths.map((distPath) => - fs.promises.cp(normalizedPath, distPath, { - recursive: true, - // dereference symlinks - dereference: true, - }), - ), - ); + await fs.promises.cp(normalizedPath, api.context.distPath, { + recursive: true, + // dereference symlinks + dereference: true, + }); } catch (err) { if (err instanceof Error) { err.message = `Copy public dir (${normalizedPath}) to dist failed:\n${err.message}`;