Answer the question
In order to leave comments, you need to log in
How to bind css-loader modules:true to html (renaming classes in css, js and html files)?
I'm trying to shorten (or obfuscate) the names of css classes using css-modules in webpack, but I get the desired result only in the css file, and in the html and js files the class names are not renamed (the original ones remain).
const path = require('path');
const HtmlPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
module.exports = {
mode: "development",
devtool: 'source-map',
entry: {
main: './src/main.js'
},
output: {
filename: 'js/[name].[hash].js',
path: path.resolve(__dirname, 'dist'),
},
plugins: [
new CleanWebpackPlugin(),
new HtmlPlugin({
template: "./src/index.html"
}),
new MiniCssExtractPlugin({
filename: 'css/[name].[hash].css'
}),
],
module: {
rules: [
{
test: /\.s[ac]ss$/i,
use: [
MiniCssExtractPlugin.loader, // extract css to file
{
loader: 'css-loader',
options: {
modules: {
localIdentName: '[sha1:hash:hex:4]'
}
}
},
"sass-loader", // Compiles Sass to CSS
],
},
],
}
};
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question