question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Docs] Need guide for css-modules

See original GitHub issue

The problem

When you enable cssModules: true options in your config css-loader

You get the next result:

body.no-webp__2343 .CollectriumSection_root__022e {
  background: url(/_next/static/images/bg_collectrium-246049879ed73fd9d55f106344d77c0b.jpg) 100% / cover fixed no-repeat;
}

body.webp__2d34 .CollectriumSection_root__022e {
  background: url(/_next/static/images/bg_collectrium-820955af9a57e6011b9180e00965b883.webp) 100% / cover fixed no-repeat;
}

To fix that I passed custom getLocalIdent function:

const getLocalIdent = require('css-loader/lib/getLocalIdent');

const cssLoaderOptions = {
  localIdentName: isProd ? '[hash:5]' : '[folder]_[local]__[hash:4]',
  getLocalIdent: (
    loaderContext,
    localIdentName,
    localName,
    options,
  ) => {
    if (localName.includes('webp')) {
      return localName;
    }

    return getLocalIdent(
      loaderContext,
      localIdentName,
      localName,
      options,
    );
  },
}

Would be great to create a section Know Issues and add this case there

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
aicommented, Aug 1, 2019

OK, let’s add option to PostCSS plugin

0reactions
aicommented, Aug 4, 2019

Release 0.2 version.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation about css-modules
A CSS Module is a CSS file in which all class names and animation names are scoped locally by default. All URLs (...
Read more >
What are CSS Modules and why do we need them?
According to the repo, CSS modules are: CSS files in which all class names and animation names are scoped locally by default. So...
Read more >
Component-Scoped Styles with CSS Modules
CSS Modules let you write styles in CSS files but consume them as JavaScript objects for additional processing and safety. CSS Modules are...
Read more >
CSS modules
Why do we need CSS modules? · reuse styles · define a higher level semantic language we can rely on to promote consistency...
Read more >
CSS modules
CSS modules do not have an official specification nor are they a browser feature. They are part of a compilation process that executes ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found