Skip to content

Commit

Permalink
fix: better handle stdin in sources (#681)
Browse files Browse the repository at this point in the history
  • Loading branch information
FractalBoy authored and evilebottnawi committed May 7, 2019
1 parent 9162e45 commit e279f2a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e279f2a

Please sign in to comment.