Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion examples/react-component-bundle-false/rslib.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ export default defineConfig({
],
output: {
target: 'web',
assetPrefix: 'auto', // TODO: move this line to packages/core/src/asset/assetConfig.ts
assetPrefix: 'auto', // TODO: move this line to packages/core/src/asset/assetConfig.ts,
sourceMap: {
js: 'source-map',
css: true,
},
},
plugins: [pluginReact(), pluginSass()],
});
10 changes: 8 additions & 2 deletions packages/core/src/css/libCssExtractLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,13 @@ export const pitch: Rspack.LoaderDefinition['pitch'] = function (

const m = new Map<string, string>();

for (const { content, filepath } of dependencies) {
for (const { content, filepath, sourceMap } of dependencies) {
let distFilepath = getRelativePath(rootDir, filepath);
const ext = extname(distFilepath);
if (ext !== 'css') {
distFilepath = distFilepath.replace(ext, '.css');
}
distFilepath = distFilepath.replace(/\.module\.css/, '_module.css');

const cssFilename = path.basename(distFilepath);
if (content.trim()) {
m.get(distFilepath)
Expand All @@ -272,6 +271,13 @@ export const pitch: Rspack.LoaderDefinition['pitch'] = function (
importCssFiles += '\n';
importCssFiles += `import "./${cssFilename}"`;
}
if (sourceMap) {
const sourceMapPath = `${distFilepath}.map`;
m.set(sourceMapPath, `${sourceMap}`);
// 将 source map 与 CSS 文件关联
const sourceMappingURL = `/*# sourceMappingURL=${cssFilename}.map */`;
m.set(distFilepath, `${m.get(distFilepath)}\n${sourceMappingURL}`);
}
}
for (const [distFilepath, content] of m.entries()) {
this.emitFile(distFilepath, content);
Expand Down
Loading