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 I found another possible issue. As the loader outputs
constit breaks bundles for legacy browsers, as theconstis not translated tovar. It happens if the application code does not consume all classes in a way so that the definition can be completely removed. By usingexport var ...the bundle works well in legacy browsers, and the loader still does it magic.