Skip to content

Commit 1cd7ff5

Browse files
committed
fix(source-map): correct CSS source map sources
1 parent 3e5f9ec commit 1cd7ff5

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

e2e/cases/source-map/basic/index.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import path, { join } from 'node:path';
33
import {
44
type Build,
55
expect,
6+
findFile,
67
getFileContent,
78
mapSourceMapPositions,
89
test,
@@ -168,6 +169,7 @@ test('should generate source maps only for CSS files', async ({ build }) => {
168169
const rsbuild = await build({
169170
config: {
170171
output: {
172+
filenameHash: false,
171173
sourceMap: {
172174
js: false,
173175
css: true,
@@ -186,4 +188,20 @@ test('should generate source maps only for CSS files', async ({ build }) => {
186188
);
187189
expect(jsMapPaths.length).toEqual(0);
188190
expect(cssMapFiles.length).toBeGreaterThan(0);
191+
192+
const cssSourceMap = findFile(files, 'index.css.map');
193+
const cssSourceContent = readFileSync(
194+
join(__dirname, './src/index.css'),
195+
'utf-8',
196+
);
197+
198+
expect(JSON.parse(files[cssSourceMap])).toEqual({
199+
file: 'static/css/index.css',
200+
// cspell: disable-next-line
201+
mappings: 'AADA',
202+
names: [],
203+
sources: ['../../../src/index.css'],
204+
sourcesContent: [cssSourceContent],
205+
version: 3,
206+
});
189207
});

packages/core/src/plugins/sourceMap.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export const pluginSourceMap = (): RsbuildPlugin => ({
5252
{
5353
test: /\.css$/,
5454
filename: '[file].map[query]',
55+
moduleFilenameTemplate: sourceMapFilenameTemplate,
5556
},
5657
]);
5758
}

0 commit comments

Comments
 (0)