Webpack is emitting incorrect sourcemaps for Sass #19034
-
So, I've been tearing my hair out over this problem with Webpack generating incorrect sourcemaps for my Sass files. When I inspect in developer tools (or use a tool like this one), the generated CSS maps to the wrong source files. This only seems to happen with my own code, not third-party Sass files (I'm including Bootstrap in my project). I've definitely narrowed the issue down to being Webpack-related: When I compile from the command line with (Dart) Sass, the emitted sourcemap is correct. I've setup an example project to prove this. The Webpack configuration there is nearly identical to my actual project's config (except the actual project's config also compiles JS, images, fonts, etc.). Compare the output in the dist directory when you run |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
Looks like there's a bug in {
type: "asset/resource",
test: /\.s?css$/,
generator: {
binary: false,
filename: pathInfo => path.basename(pathInfo.filename).replace(/\.scss/gi, ".css")
},
use: [
{
loader: "sass-loader",
options: {
sassOptions: {
quietDeps: true,
silenceDeprecations: [
"import",
"color-functions",
"global-builtin",
"mixed-decls",
]
},
sourceMap: true,
},
},
],
}, i.e. ask webpack generate scss like an asset it will contain the correct source maps, For debug goals - comment console.log('prev', map.mappings);
try {
result = await postcss(plugins).process(content, {
hideNothingWarning: true,
from: resourcePath,
to: resourcePath,
map: options.sourceMap
? {
prev: map ? normalizeSourceMap(map, resourcePath) : null,
inline: false,
annotation: false,
}
: false,
});
} catch (error) {
if (error.file) {
this.addDependency(error.file);
}
callback(
error.name === "CssSyntaxError" ? syntaxErrorFactory(error) : error,
);
return;
}
console.log('generated', result.map.toJSON().mappings); And you will see that |
Beta Was this translation helpful? Give feedback.
-
@rhaglennydd That intresting because if you set /cc @nex3 Is |
Beta Was this translation helpful? Give feedback.
-
Sorry for taking awhile to get back to this. I am now getting correct sourcemaps after specifying "expanded" for sassOptions.style. I have updated the GitHub project. |
Beta Was this translation helpful? Give feedback.
Sorry for taking awhile to get back to this. I am now getting correct sourcemaps after specifying "expanded" for sassOptions.style. I have updated the GitHub project.