-
Notifications
You must be signed in to change notification settings - Fork 69
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
Source Maps not working with Webpack 4.8 #53
Comments
Just figured it out! (this helped with a useful snippet: cssnano/cssnano#302) Actually this is not a bug, but can be improved (with docs or better defaults to identify if there are settings in webpack to generate source-maps...) You just need to set the new OptimizeCSSAssetsPlugin({
cssProcessorOptions: {
map: {
inline: false
}
}
}) If no other cssProcessor is specified, then Maybe docs improvements could be made so that it would become clearer on how to use cssProcessorOptions (at least for the default processor, cssnano). Or maybe this plugin could somehow know if the webpack setup is configured to use source-maps or if the css itself has it to set map property to cssnano in that case (sorry if I'm talking silliness, I'm not a webpack nor a cssnano expert at all... It was just a painful debugging session...) |
Just created the PR above and added some docs about source-maps. |
I agree that the "source map" section should be added to the README to help people who encounter this problem. Thanks for the help :) PS: You didn't open a PR on this repo (it was opened on the forked repo). PS2: Do you mind if i change the wording of the README a bit on your PR? |
Woops! xP |
fixed it. @NMFR could you review it? |
@hbobenicio unfortunately your solution only partially solve the problem 😢 filename reference are not correct, here is a test repository (please read the readme file) |
I see... |
Same issue here... |
I found a workaround: if you will use |
@pldg Finally got some time to take a look at your test repo. new MiniCssExtractPlugin({
filename: 'style.min.css' // or 'style.css' if preferred...
}), instead of this new MiniCssExtractPlugin({}), Then you get the minified css named Gonna contribute to your test repo. Can you se other concerns about the inline workaround? |
@pldg Just created a PR to your test repo. Could you check it and re-test it for us? |
@hbobenicio set a specific filename doesn't solve the problem |
Yes... I see now your point, @pldg . You're totally correct, this is still buggy. Sorry for my blidness! And thanks for taking the time to explaining it. |
@NMFR @frenzzy I've tested the new release but the bug is not solved. This issue should be open. Have a look to my repository, please read the readme file, clone the repo and run the test yourself. Thanks. |
Have you read PostCSS sourcemaps options section? new OptimizeCSSAssetsPlugin({
cssProcessorOptions: {
map: {
inline: true,
}
}
}) If you need external source maps, use: new OptimizeCSSAssetsPlugin({
cssProcessorOptions: {
map: {
inline: false,
annotation: true,
}
}
}) |
Or we may add a special For example: new OptimizeCSSAssetsPlugin({ sourceMap: true }) new OptimizeCSSAssetsPlugin({ sourceMap: 'inline' }) PR is welcome :) |
Thanks @frenzzy adding the code you suggest works fine! |
Thanks for all the effort to get the source maps working. Using the tips here and installing the However, there is still something a bit off with the paths that are generated and placed into the map file. When I do a non production build without using this optimize css plugin the generated map file has entries in it that look like this: {"version":3,
"sources":[
"webpack:///./src/components/controlbar/css/endpoint-mode-selector.less",
"webpack:///./src/index.css",
"webpack:///./src/assets/Roboto-local.css", When I do a production build using this optimize css plugin the map file looks like this: {"version":3,
"sources":[
"/data/hbird/src/components/controlbar/css/endpoint-mode-selector.less",
"/data/hbird/src/index.css",
"/data/hbird/src/assets/Roboto-local.css", I am using the config suggested above. new OptimizeCSSAssetsPlugin({
cssProcessorOptions: {
map: {
inline: false,
annotation: true,
}
}
}) This still works in the browser, but the file system mappings look a bit odd in the developer tools. Is there some way to get the map file to be generated using the same Here is a snippet of the webpack config ( {
test: /\.less$/,
include: props.srcRoot,
use: [
{loader: extractCSS ? MiniCssExtractPlugin.loader : "style-loader"},
{loader: "css-loader", options: {sourceMap: genSourceMaps}},
{loader: "less-loader", options: {sourceMap: genSourceMaps}}
]
}, |
@medington you can try optimize-cssnano-plugin which is more accurate with source maps. |
Is this problem solved? My sourcempas is still empty. |
I would like to fix the issue described by @medington for the sake of privacy and consistency. Note that customizing https://webpack.js.org/configuration/output/#outputdevtoolmodulefilenametemplate doesn't help. |
I found @frenzzy had the solution, except for one problem. While it did finally enable source maps in production, they were not fully accurate. Many references in the source map were correct, but it was sometimes pointing at things like my So if anyone else has this issue too, a quick install of the latest |
My version of optimize-css-assets-webpack-plugin: 4.0.1
The issue I'm facing is the same as described here:
webpack-contrib/mini-css-extract-plugin#141
In summary, I'm defining source-maps on my configuration. I'm also using MiniCssExtractPlugin to extract the css modules to a specific bundle, but when using
optimize-css-assets-webpack-plugin
on webpacks 4optimization.minimizer
, the source-maps are not generated. Here is a snippet:Maybe optimize-css-assets-webpack-plugin is truncating source-maps some how?!
The text was updated successfully, but these errors were encountered: