@@ -159,7 +159,6 @@ function getSassOptions(
159
159
// Pretty complicated... :(
160
160
options . sourceMap = true ;
161
161
options . outFile = path . join ( loaderContext . rootContext , 'style.css.map' ) ;
162
- // options.sourceMapRoot = process.cwd();
163
162
options . sourceMapContents = true ;
164
163
options . omitSourceMapUrl = true ;
165
164
options . sourceMapEmbed = false ;
@@ -507,15 +506,33 @@ function getURLType(source) {
507
506
return ABSOLUTE_SCHEME . test ( source ) ? 'absolute' : 'path-relative' ;
508
507
}
509
508
510
- function absolutifySourceMapSource ( sourceRoot , source ) {
511
- const sourceType = getURLType ( source ) ;
509
+ function normalizeSourceMap ( map , rootContext ) {
510
+ const newMap = map ;
512
511
513
- // Do no touch `scheme-relative`, `path-absolute` and `absolute` types
514
- if ( sourceType === 'path-relative' ) {
515
- return path . resolve ( sourceRoot , path . normalize ( source ) ) ;
516
- }
512
+ // result.map.file is an optional property that provides the output filename.
513
+ // Since we don't know the final filename in the webpack build chain yet, it makes no sense to have it.
514
+ // eslint-disable-next-line no-param-reassign
515
+ delete newMap . file ;
516
+
517
+ // eslint-disable-next-line no-param-reassign
518
+ newMap . sourceRoot = '' ;
519
+
520
+ // node-sass returns POSIX paths, that's why we need to transform them back to native paths.
521
+ // This fixes an error on windows where the source-map module cannot resolve the source maps.
522
+ // @see https://github.com/webpack-contrib/sass-loader/issues/366#issuecomment-279460722
523
+ // eslint-disable-next-line no-param-reassign
524
+ newMap . sources = newMap . sources . map ( ( source ) => {
525
+ const sourceType = getURLType ( source ) ;
526
+
527
+ // Do no touch `scheme-relative`, `path-absolute` and `absolute` types
528
+ if ( sourceType === 'path-relative' ) {
529
+ return path . resolve ( rootContext , path . normalize ( source ) ) ;
530
+ }
531
+
532
+ return source ;
533
+ } ) ;
517
534
518
- return source ;
535
+ return newMap ;
519
536
}
520
537
521
538
export {
@@ -524,5 +541,5 @@ export {
524
541
getWebpackResolver ,
525
542
getWebpackImporter ,
526
543
getRenderFunctionFromSassImplementation ,
527
- absolutifySourceMapSource ,
544
+ normalizeSourceMap ,
528
545
} ;
0 commit comments