1

I am using webpack v5.74.0.

I want to add a custom class to all CSS rules at build time using webpack. Example for reference

.input-text {color: red} should become .container .input-text {color: red}

Custom wrapper class needs to be added inside less files. Not able to find any loader in webpack to prefix this container class.

Please suggest.

asked Aug 10, 2022 at 12:25

1 Answer 1

1

try the below code in your webpack config to add a wrapper class for all classes present in your project.

module: {
 rules: [
 {
 test: /\.(css|less)$/i,
 use: [
 {
 loader: "style-loader",
 },
 {
 loader: "css-loader",
 },
 {
 loader: "postcss-loader",
 options: {
 postcssOptions: {
 plugins: {
 "postcss-increase-specificity": {
 stackableRoot: `.container`,
 repeat: 1,
 },
 },
 },
 },
 },
 {
 loader: "less-loader",
 options: {
 lessOptions: {
 javascriptEnabled: true,
 },
 },
 },
 ],
 },
 ],
 }
Paul Ghiran
1,2331 gold badge16 silver badges30 bronze badges
answered Dec 27, 2022 at 12:37
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.