Sourcemap doesn't work with devtool option contain "eval"
See original GitHub issue- Operating System:
- Node Version: 10.15.2
- NPM Version: 6.4.1
- webpack Version: 4.41.6
- mini-css-extract-plugin Version: 0.9.0
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
// webpack.config.js
module.exports = {
mode: 'development', // 'production'
devtool: 'cheap-module-source-map',
entry: {
'learn': './src/main.js',
},
module: {
rules: [ // 添加对模块处理特定规则
{
test: /\.s[ac]ss$/i,
use: [{
loader: MiniCssExtractPlugin.loader,
options: {hmr: true}
},
{loader: 'css-loader', options: {sourceMap: true}},
{loader: 'sass-loader', options: {sourceMap: true}},]
}
]
},
plugins: [
new MiniCssExtractPlugin({
filename: '[name].css'
}),
new HtmlWebpackPlugin(),
],
devServer: {
port: 9000,
hot: true
}
}
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 https://github.com/webpack-contrib/mini-css-extract-plugin/issues/29#issuecomment-382424129
new webpack.SourceMapDevToolPlugin({
filename: "[file].map",
exclude: ["/vendor/"]
}),
```js
Issue Analytics
- State:
- Created 3 years ago
- Reactions:10
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Webpack - devtool source-map VS eval-source-map
it looks like this person has better luck using source-map for CSS file mapping whereas eval-source-map is more helpful for JS files. I...
Read more >Devtool - webpack
devtool performance production quality
(none) build: fastest rebuild: fastest yes bundle
eval build: fast rebuild: fastest no generated
eval‑cheap‑source‑map build: ok rebuild: fast no transformed
Read more >Source Maps | webpack surviveJS - GitHub Pages
Source maps solve this problem by providing a mapping between the original and the ... eval-source-map is the highest quality option of the...
Read more >Source Maps - SurviveJS
Often eval is the starting point and webpack issue #2145 recommends ... To override this, you have to prefix your source map option...
Read more >EN - Webpackjs - Devtool.pdf - Repository [Root Me
Never use both the devtool option and plugin together. ... eval fastest fastest no generated code eval-cheap-source-map ... You have to make sure...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yes, it is limitation,
eval
doesn’t work with CSS, you need to usesource-map
, we need documented itFollow-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:
Normally we would turn off the
devtool
option, but if we are using an “eval-*-source-map” as its value, it is applying a different pluginEvalSourceMapDevToolPlugin
. As long as the plugin we add is NOT touching JS files, we won’t interfere that option: https://github.com/webpack/webpack/blob/v5.67.0/lib/WebpackOptionsApply.js#L225-L246This also solves issue #29 and seems more elegant than both the original and my previous solution.