File tree 2 files changed +9
-7
lines changed
2 files changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -90,21 +90,23 @@ class CssWriter {
90
90
91
91
this . sourcemap = ( file , mapping ) => {
92
92
const ref = this . emit ( file , this . code ) ;
93
- const filename = context . getFileName ( ref ) ;
93
+ const filename = context . getFileName ( ref ) ; // may be "assets/[name][ext]"
94
94
95
- const mapfile = `${ filename } .map` ;
95
+ const mapfile = `${ filename } .map` ; // may be "assets/[name][ext]"
96
96
const toRelative = src => path . relative ( path . dirname ( file ) , src ) ;
97
97
98
98
if ( bundle [ filename ] ) {
99
- bundle [ filename ] . source += `\n/*# sourceMappingURL=${ mapfile } */` ;
99
+ // use `basename` because files are siblings
100
+ // aka, avoid `sourceMappingURL=assets/bundle.css.map` from `assets/bundle.css`
101
+ bundle [ filename ] . source += `\n/*# sourceMappingURL=${ path . basename ( mapfile ) } */` ;
100
102
} else {
101
103
// This should not ever happen, but just in case...
102
104
return this . warn ( `Missing "${ filename } " ("${ file } ") in bundle; skipping sourcemap!` ) ;
103
105
}
104
106
105
107
const source = JSON . stringify ( {
106
108
...mapping ,
107
- file : filename ,
109
+ file : path . basename ( filename ) , //=> sibling file
108
110
sources : mapping . sources . map ( toRelative ) ,
109
111
} , null , isDev ? 2 : 0 ) ;
110
112
Original file line number Diff line number Diff line change @@ -101,7 +101,7 @@ test('does not generate a CSS sourcemap by default', async () => {
101
101
assetFileNames : '[name][extname]' ,
102
102
} ) ;
103
103
104
- assert . is ( css . code . includes ( 'sourceMappingURL' ) , false ) ;
104
+ assert . not . match ( css . code , 'sourceMappingURL' ) ;
105
105
assert . is ( css . map , false ) ;
106
106
} ) ;
107
107
@@ -495,8 +495,8 @@ test('ensures sourcemap and original files point to each other\'s hashed filenam
495
495
const data1 = fs . readFileSync ( path . join ( assets , file ) , 'utf-8' ) ;
496
496
const data2 = fs . readFileSync ( path . join ( assets , sourcemap ) , 'utf-8' ) ;
497
497
498
- assert . match ( data1 , sourcemap , 'file has `sourcemap` reference' ) ;
499
- assert . match ( data2 , file , 'sourcemap has `file` reference' ) ;
498
+ assert . match ( data1 , `sourceMappingURL= ${ sourcemap } ` , 'file has `sourcemap` reference' ) ;
499
+ assert . match ( data2 , `" file":" ${ file } "` , 'sourcemap has `file` reference' ) ;
500
500
} ) ;
501
501
502
502
test ( 'handles filenames that happen to contain .svelte' , async ( ) => {
You can’t perform that action at this time.
0 commit comments