File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed
examples/react-component-bundle-false Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -32,7 +32,11 @@ export default defineConfig({
3232 ] ,
3333 output : {
3434 target : 'web' ,
35- assetPrefix : 'auto' , // TODO: move this line to packages/core/src/asset/assetConfig.ts
35+ assetPrefix : 'auto' , // TODO: move this line to packages/core/src/asset/assetConfig.ts,
36+ sourceMap : {
37+ js : 'source-map' ,
38+ css : true ,
39+ } ,
3640 } ,
3741 plugins : [ pluginReact ( ) , pluginSass ( ) ] ,
3842} ) ;
Original file line number Diff line number Diff line change @@ -255,14 +255,13 @@ export const pitch: Rspack.LoaderDefinition['pitch'] = function (
255255
256256 const m = new Map < string , string > ( ) ;
257257
258- for ( const { content, filepath } of dependencies ) {
258+ for ( const { content, filepath, sourceMap } of dependencies ) {
259259 let distFilepath = getRelativePath ( rootDir , filepath ) ;
260260 const ext = extname ( distFilepath ) ;
261261 if ( ext !== 'css' ) {
262262 distFilepath = distFilepath . replace ( ext , '.css' ) ;
263263 }
264264 distFilepath = distFilepath . replace ( / \. m o d u l e \. c s s / , '_module.css' ) ;
265-
266265 const cssFilename = path . basename ( distFilepath ) ;
267266 if ( content . trim ( ) ) {
268267 m . get ( distFilepath )
@@ -272,6 +271,13 @@ export const pitch: Rspack.LoaderDefinition['pitch'] = function (
272271 importCssFiles += '\n' ;
273272 importCssFiles += `import "./${ cssFilename } "` ;
274273 }
274+ if ( sourceMap ) {
275+ const sourceMapPath = `${ distFilepath } .map` ;
276+ m . set ( sourceMapPath , `${ sourceMap } ` ) ;
277+ // 将 source map 与 CSS 文件关联
278+ const sourceMappingURL = `/*# sourceMappingURL=${ cssFilename } .map */` ;
279+ m . set ( distFilepath , `${ m . get ( distFilepath ) } \n${ sourceMappingURL } ` ) ;
280+ }
275281 }
276282 for ( const [ distFilepath , content ] of m . entries ( ) ) {
277283 this . emitFile ( distFilepath , content ) ;
You can’t perform that action at this time.
0 commit comments