Skip to content

Commit 097fcad

Browse files
authored
feat: hint assets emit name conflict (#6559)
1 parent 72fed9f commit 097fcad

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { expect, rspackTest } from '@e2e/helper';
2+
3+
rspackTest(
4+
'should print output.filename hints as expected',
5+
async ({ build }) => {
6+
const rsbuild = await build({
7+
catchBuildError: true,
8+
});
9+
10+
expect(rsbuild.buildError).toBeTruthy();
11+
12+
await rsbuild.expectLog(
13+
'You may need to adjust output.filename configuration to prevent name conflicts.',
14+
);
15+
},
16+
);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { defineConfig } from '@rsbuild/core';
2+
3+
export default defineConfig({
4+
output: {
5+
filename: {
6+
image: 'image.png',
7+
},
8+
dataUriLimit: 0,
9+
},
10+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import icon from '@e2e/assets/icon.png';
2+
import image from '@e2e/assets/image.png';
3+
4+
console.log(icon, image);

packages/core/src/helpers/format.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,18 @@ function hintUnknownFiles(message: string): string {
141141
return message;
142142
}
143143

144+
const hintAssetsConflict = (message: string): string => {
145+
const hint = 'Multiple assets emit different content to the same filename';
146+
147+
if (message.indexOf(hint) === -1) {
148+
return message;
149+
}
150+
151+
const extraMessage = `You may need to adjust ${color.yellow('output.filename')} configuration to prevent name conflicts. (See ${color.yellow('https://rsbuild.rs/config/output/filename')})`;
152+
153+
return `${message}\n${extraMessage}`;
154+
};
155+
144156
/**
145157
* Add node polyfill tip when failed to resolve node built-in modules.
146158
*/
@@ -250,6 +262,7 @@ export function formatStatsError(stats: StatsError): string {
250262

251263
message = hintUnknownFiles(message);
252264
message = hintNodePolyfill(message);
265+
message = hintAssetsConflict(message);
253266

254267
let lines = message.split('\n');
255268

0 commit comments

Comments
 (0)