-
-
Notifications
You must be signed in to change notification settings - Fork 384
Sourcemap doesn't work with devtool option contain "eval" #529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @sokra , has any solution? |
Yes, it is limitation, |
After hacking around a while, I have found that it is actually possible to have CSS source maps inlined when devtool option contains "eval". To be precise, this plugin currently only supports source maps that are emitted in separate files. In our case, this is not possible since our mini-css-extract-plugin/src/index.js Line 1410 in be75c50
... with: const result = new ConcatSource(externalsSource, source);
const m = result.map();
// if the source map information is available...
if (m != null) {
const encoded = Buffer.from(JSON.stringify(m)).toString('base64');
const footer = `/*# sourceMappingURL=data:application/json;charset=utf-8;base64,${encoded} */`;
result.add(new RawSource(footer));
}
return result; And we have embedded the source map. Now the devtool can detect it properly. |
Follow-up: After reading webpack's source code a little bit more, I manage to adjust the configuration accordingly so it produces the inline source map instead, without touching the source code of mini-css-extract-plugin: {
/* ... */
plugins: [
new MiniCssExtractPlugin(),
new webpack.SourceMapDevToolPlugin({
test: /\.css$/i,
filename: null,
append: '/*# sourceMappingURL=[url] */',
})
]
} Normally we would turn off the This also solves issue #29 and seems more elegant than both the original and my previous solution. |
It really works! Nice solution |
@alexander-akait Is there a reason the proposed solution above by @andy0130tw is not already implemented by default to get |
@caseyjhol You can just set |
@alexander-akait I just tested that, and can confirm that the resulting output is not the same. Webpack: v5.98.0
What does work is the above suggested SourceMapDevToolPlugin configuration, but only if What else might I be missing? |
Eval source maps works only with JS, it is by design, what is why you need include
So such things will be easy to setup |
Ah, I see. Thank you for clarifying. Is there an estimated timeline for that feature? If not, is it a feature the team would be open to pull requests for? As a shorthand, it would be great if we could simply set Thanks again for the added insight. |
Yeah, PR welcome, we didn't do it only because no one sent this improvement. |
Glad to hear that my solution was helpful. Although I left the project in early 2024 that used this plugin-based workaround, I believe that it should still be working fine. If anyone can test it and draft a PR with proper attribution, I would greatly appreciate it. |
Expected Behavior
Use the devtool options with "eval" such as "cheap-module-eval-source-map", the extract css file can map to the really css or sass file.

Actual Behavior
My entry file 'main.js' which import 'testSass.scss', with the devtool options "cheap-module-eval-source-map" to get the fast rebuild . But it'can not map the body style to the real sass file.

If I change devtool to "cheap-module-source-map" without 'eval', It works.
Code
How Do We Reproduce?
You can use the config above . If cannot reproduce , I will give a repo later.
Addition
I found an hack with add the sourcemapPlugin with devtools in #29 (comment)
The text was updated successfully, but these errors were encountered: