Skip to content

Commit 9863b72

Browse files
authored
Revert "fix: should copy publicDir to the environment distDir when multiple environments (#4220)" (#4240)
1 parent 058993d commit 9863b72

File tree

2 files changed

+6
-53
lines changed

2 files changed

+6
-53
lines changed

e2e/cases/server/public-dir/publicDir.test.ts

-39
Original file line numberDiff line numberDiff line change
@@ -170,45 +170,6 @@ test('should serve publicDir for preview server correctly', async ({
170170
await rsbuild.close();
171171
});
172172

173-
test('should copy publicDir to the environment distDir when multiple environments', async () => {
174-
await fse.outputFile(join(__dirname, 'public', 'test-temp-file.txt'), 'a');
175-
176-
const rsbuild = await build({
177-
cwd,
178-
rsbuildConfig: {
179-
environments: {
180-
web1: {
181-
output: {
182-
distPath: {
183-
root: 'dist-build-web-1',
184-
},
185-
},
186-
},
187-
web2: {
188-
output: {
189-
distPath: {
190-
root: 'dist-build-web-2',
191-
},
192-
},
193-
},
194-
},
195-
},
196-
});
197-
const files = await rsbuild.unwrapOutputJSON();
198-
const filenames = Object.keys(files);
199-
200-
expect(
201-
filenames.some((filename) =>
202-
filename.includes('dist-build-web-1/test-temp-file.txt'),
203-
),
204-
).toBeTruthy();
205-
expect(
206-
filenames.some((filename) =>
207-
filename.includes('dist-build-web-2/test-temp-file.txt'),
208-
),
209-
).toBeTruthy();
210-
});
211-
212173
test('should serve publicDir for preview server with assetPrefix correctly', async ({
213174
page,
214175
}) => {

packages/core/src/plugins/server.ts

+6-14
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const pluginServer = (): RsbuildPlugin => ({
2323

2424
api.onAfterStartDevServer(onStartServer);
2525
api.onAfterStartProdServer(onStartServer);
26-
api.onBeforeBuild(async ({ isFirstCompile, environments }) => {
26+
api.onBeforeBuild(async ({ isFirstCompile }) => {
2727
if (!isFirstCompile) {
2828
return;
2929
}
@@ -45,22 +45,14 @@ export const pluginServer = (): RsbuildPlugin => ({
4545
continue;
4646
}
4747

48-
const distPaths = [
49-
...new Set(Object.values(environments).map((e) => e.distPath)),
50-
];
51-
5248
try {
5349
// async errors will missing error stack on copy, move
5450
// https://github.com/jprichardson/node-fs-extra/issues/769
55-
await Promise.all(
56-
distPaths.map((distPath) =>
57-
fs.promises.cp(normalizedPath, distPath, {
58-
recursive: true,
59-
// dereference symlinks
60-
dereference: true,
61-
}),
62-
),
63-
);
51+
await fs.promises.cp(normalizedPath, api.context.distPath, {
52+
recursive: true,
53+
// dereference symlinks
54+
dereference: true,
55+
});
6456
} catch (err) {
6557
if (err instanceof Error) {
6658
err.message = `Copy public dir (${normalizedPath}) to dist failed:\n${err.message}`;

0 commit comments

Comments
 (0)