diff --git a/lib/loader.js b/lib/loader.js index fa926375..7ffdc5e4 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -81,12 +81,21 @@ function sassLoader(content) { // Since we don't know the final filename in the webpack build chain yet, it makes no sense to have it. // eslint-disable-next-line no-param-reassign delete result.map.file; - // The first source is 'stdin' according to node-sass because we've used the data input. + // One of the sources is 'stdin' according to dart-sass/node-sass because we've used the data input. // Now let's override that value with the correct relative path. // Since we specified options.sourceMap = path.join(process.cwd(), "/sass.map"); in normalizeOptions, // we know that this path is relative to process.cwd(). This is how node-sass works. // eslint-disable-next-line no-param-reassign - result.map.sources[0] = path.relative(process.cwd(), resourcePath); + const stdinIndex = result.map.sources.findIndex( + (source) => source.indexOf('stdin') !== -1 + ); + + if (stdinIndex !== -1) { + result.map.sources[stdinIndex] = path.relative( + process.cwd(), + resourcePath + ); + } // node-sass returns POSIX paths, that's why we need to transform them back to native paths. // This fixes an error on windows where the source-map module cannot resolve the source maps. // @see https://github.com/webpack-contrib/sass-loader/issues/366#issuecomment-279460722