fix(webpack): fix css sourceMap option#3272
fix(webpack): fix css sourceMap option#3272mikejpeters wants to merge 2 commits intoangular:masterfrom mikejpeters:fix-css-sourcemaps
Conversation
CSS source maps were not correctly generated because `sourceMap` option is case sensitive. Also several workarounds are necessary with LoaderOptionsPlugin.
| postcss: [ autoprefixer() ] | ||
| postcss: [ autoprefixer() ], | ||
| // workaround for https://github.com/webpack/css-loader/issues/340 | ||
| context: path.resolve(__dirname, './'), |
There was a problem hiding this comment.
Are you sure you want to use __dirname here?
There was a problem hiding this comment.
It's the same value passed to context earlier in this file.
There was a problem hiding this comment.
@hansl Solving this bug is quite important IMHO. Could you please take a closer look and propose an alternative if using __dirname is not acceptable?
I've tried the fix and it and works fine (at last).
Thanks a lot!
There was a problem hiding this comment.
Alternative: project root.
The reason is the __dirname is the path to this file, but it might actually not be in the same directory than the project (for example, when you npm link the CLI). I think the correct solution is to use the project root.
Note that tutorial use __dirname because their webpack.config.js are at the root of their project. So in their case it's the valid thing to do.
Also, path.resolve(__dirname, '.') does nothing; just put the path in there.
There was a problem hiding this comment.
What I have done is just a simple workaround for the fact that loader options plugin makes the original webpack config inaccessible to the other plugins. Probably the most correct way to apply the workaround would be to assign the entire webpack config to a var, so that the values can be re-used like this:
var webpackConfig = {
...
context: path.resolve(__dirname, './'),
...
};
webpackConfig.plugins.push(
new webpack.LoaderOptionsPlugin({
test: /\.(css|scss|sass|less|styl)$/,
options: {
postcss: [ autoprefixer() ],
context: webpackConfig.context, // workaround
output: {
path: webpackConfig.output.path // workaround
}
}
})
});
return webpackConfig;I did not do this simply because I wanted to keep the changes I make in this merge request as simple as possible. That's why I copied the exact config values from higher up in this same file. If you want those values changed I think it should be a separate merge request.
| ] | ||
| ], | ||
| // workaround for https://github.com/webpack/css-loader/issues/340 | ||
| context: path.resolve(__dirname, './'), |
|
Is it possible to add an e2e test so we avoid regressoins in the future? |
|
Superseded by #3402, it includes the fixes found here and more work. |
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
CSS source maps were not correctly generated because
sourceMapoption is case sensitive.Also several workarounds are necessary with LoaderOptionsPlugin.
Fixes #2020