This loader optimizes the output of mini-css-extract-plugin
and/or css-loader
,
entirely removing the potentially large CSS classname mappings normally inlined into your bundle when using CSS Modules.
Run npm install constant-locals-loader
, then make these changes in your Webpack config:
module.exports = {
module: {
rules: [
{
test: /\.css$/,
use: [
+ 'constant-locals-loader',
{
loader: MiniCSSExtractPlugin.loader,
options: {
+ esModule: true,
},
},
{
loader: 'css-loader',
options: {
modules: true,
+ localsConvention: 'camelCaseOnly',
+ esModule: true,
},
},
],
},
],
},
plugins: [new MiniCSSExtractPlugin({})],
};
@developit this is really nice. I did face an issue though. I have a project, in which we combine all of our CSS using
cacheGroups
, to avoid splitting it in lots of small chunks, as most of our CSS is the same for all chunks. But when using with this loader, it seems like the loader does nothing - if I remove the cacheGroup, everything works as expected, but we end up with multiple .css files. Is this working by design, or something that could/should be addressed?