From 1cd7ff5e0ddccf328e61939a26ef61a968692721 Mon Sep 17 00:00:00 2001 From: neverland Date: Tue, 28 Oct 2025 17:47:08 +0800 Subject: [PATCH] fix(source-map): correct CSS source map sources --- e2e/cases/source-map/basic/index.test.ts | 18 ++++++++++++++++++ packages/core/src/plugins/sourceMap.ts | 1 + 2 files changed, 19 insertions(+) diff --git a/e2e/cases/source-map/basic/index.test.ts b/e2e/cases/source-map/basic/index.test.ts index eb02a4b51e..0899b59bcb 100644 --- a/e2e/cases/source-map/basic/index.test.ts +++ b/e2e/cases/source-map/basic/index.test.ts @@ -3,6 +3,7 @@ import path, { join } from 'node:path'; import { type Build, expect, + findFile, getFileContent, mapSourceMapPositions, test, @@ -168,6 +169,7 @@ test('should generate source maps only for CSS files', async ({ build }) => { const rsbuild = await build({ config: { output: { + filenameHash: false, sourceMap: { js: false, css: true, @@ -186,4 +188,20 @@ test('should generate source maps only for CSS files', async ({ build }) => { ); expect(jsMapPaths.length).toEqual(0); expect(cssMapFiles.length).toBeGreaterThan(0); + + const cssSourceMap = findFile(files, 'index.css.map'); + const cssSourceContent = readFileSync( + join(__dirname, './src/index.css'), + 'utf-8', + ); + + expect(JSON.parse(files[cssSourceMap])).toEqual({ + file: 'static/css/index.css', + // cspell: disable-next-line + mappings: 'AADA', + names: [], + sources: ['../../../src/index.css'], + sourcesContent: [cssSourceContent], + version: 3, + }); }); diff --git a/packages/core/src/plugins/sourceMap.ts b/packages/core/src/plugins/sourceMap.ts index 853bf69c8b..647d2c0c52 100644 --- a/packages/core/src/plugins/sourceMap.ts +++ b/packages/core/src/plugins/sourceMap.ts @@ -52,6 +52,7 @@ export const pluginSourceMap = (): RsbuildPlugin => ({ { test: /\.css$/, filename: '[file].map[query]', + moduleFilenameTemplate: sourceMapFilenameTemplate, }, ]); }