@@ -159,7 +159,6 @@ function getSassOptions(
159159 // Pretty complicated... :(
160160 options . sourceMap = true ;
161161 options . outFile = path . join ( loaderContext . rootContext , 'style.css.map' ) ;
162- // options.sourceMapRoot = process.cwd();
163162 options . sourceMapContents = true ;
164163 options . omitSourceMapUrl = true ;
165164 options . sourceMapEmbed = false ;
@@ -507,15 +506,33 @@ function getURLType(source) {
507506 return ABSOLUTE_SCHEME . test ( source ) ? 'absolute' : 'path-relative' ;
508507}
509508
510- function absolutifySourceMapSource ( sourceRoot , source ) {
511- const sourceType = getURLType ( source ) ;
509+ function normalizeSourceMap ( map , rootContext ) {
510+ const newMap = map ;
512511
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+ } ) ;
517534
518- return source ;
535+ return newMap ;
519536}
520537
521538export {
@@ -524,5 +541,5 @@ export {
524541 getWebpackResolver ,
525542 getWebpackImporter ,
526543 getRenderFunctionFromSassImplementation ,
527- absolutifySourceMapSource ,
544+ normalizeSourceMap ,
528545} ;
0 commit comments