Skip to content

Commit 4dd1b01

Browse files
committed
chore: add test case
1 parent 8cc4cec commit 4dd1b01

File tree

6 files changed

+43
-5
lines changed

6 files changed

+43
-5
lines changed

examples/react-component-bundle-false/rslib.config.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ export default defineConfig({
3333
output: {
3434
target: 'web',
3535
assetPrefix: 'auto', // TODO: move this line to packages/core/src/asset/assetConfig.ts,
36-
sourceMap: {
37-
js: 'source-map',
38-
css: true,
39-
},
4036
},
4137
plugins: [pluginReact(), pluginSass()],
4238
});

packages/core/src/css/libCssExtractLoader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ export const pitch: Rspack.LoaderDefinition['pitch'] = function (
274274
if (sourceMap) {
275275
const sourceMapPath = `${distFilepath}.map`;
276276
m.set(sourceMapPath, `${sourceMap}`);
277-
// source map CSS 文件关联
277+
// Associate the source map with the CSS file
278278
const sourceMappingURL = `/*# sourceMappingURL=${cssFilename}.map */`;
279279
m.set(distFilepath, `${m.get(distFilepath)}\n${sourceMappingURL}`);
280280
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "sourcemap-css-test",
3+
"version": "1.0.0",
4+
"private": true,
5+
"type": "module"
6+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { defineConfig } from '@rslib/core';
2+
import { generateBundleEsmConfig } from 'test-helper';
3+
4+
export default defineConfig({
5+
lib: [generateBundleEsmConfig({ bundle: false })],
6+
source: {
7+
entry: {
8+
index: ['./src/index.css'],
9+
},
10+
},
11+
output: {
12+
target: 'web',
13+
sourceMap: {
14+
css: true,
15+
},
16+
},
17+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.hello-world {
2+
color: #bfa;
3+
}

tests/integration/sourcemap/index.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,19 @@ test('should generate js inline sourcemap: inline-cheap-module-source-map', asyn
4141

4242
expect(code[0]).toContain('//# sourceMappingURL=data:application/json');
4343
});
44+
45+
test('should generate css sourcemap file', async () => {
46+
const fixturePath = join(__dirname, 'css');
47+
const { contents } = await buildAndGetResults({ fixturePath, type: 'css' });
48+
const files = Object.keys(contents.esm);
49+
const code = Object.values(contents.esm);
50+
51+
expect(files).toMatchInlineSnapshot(`
52+
[
53+
"<ROOT>/tests/integration/sourcemap/css/dist/esm/index.css",
54+
"<ROOT>/tests/integration/sourcemap/css/dist/esm/index.css.map",
55+
]
56+
`);
57+
58+
expect(code[0]).toContain('/*# sourceMappingURL=index.css.map */');
59+
});

0 commit comments

Comments
 (0)