Skip to content

Commit e279f2a

Browse files
FractalBoyevilebottnawi
authored andcommitted
fix: better handle stdin in sources (#681)
1 parent 9162e45 commit e279f2a

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

lib/loader.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,21 @@ function sassLoader(content) {
8181
// Since we don't know the final filename in the webpack build chain yet, it makes no sense to have it.
8282
// eslint-disable-next-line no-param-reassign
8383
delete result.map.file;
84-
// The first source is 'stdin' according to node-sass because we've used the data input.
84+
// One of the sources is 'stdin' according to dart-sass/node-sass because we've used the data input.
8585
// Now let's override that value with the correct relative path.
8686
// Since we specified options.sourceMap = path.join(process.cwd(), "/sass.map"); in normalizeOptions,
8787
// we know that this path is relative to process.cwd(). This is how node-sass works.
8888
// eslint-disable-next-line no-param-reassign
89-
result.map.sources[0] = path.relative(process.cwd(), resourcePath);
89+
const stdinIndex = result.map.sources.findIndex(
90+
(source) => source.indexOf('stdin') !== -1
91+
);
92+
93+
if (stdinIndex !== -1) {
94+
result.map.sources[stdinIndex] = path.relative(
95+
process.cwd(),
96+
resourcePath
97+
);
98+
}
9099
// node-sass returns POSIX paths, that's why we need to transform them back to native paths.
91100
// This fixes an error on windows where the source-map module cannot resolve the source maps.
92101
// @see https://github.com/webpack-contrib/sass-loader/issues/366#issuecomment-279460722

0 commit comments

Comments
 (0)