Skip to content

Resolve css-loader v4 + babel-plugin-react-css-modules incompatibility #581

@Mr0grog

Description

@Mr0grog

See also #580.

I messed up when checking dependency updates today, and upgrading from css-loader v3.6.0 to v4.2.0 totally hosed the layout. The core problem is that in v4, css-loader and babel-plugin-react-css-modules generate different hashes for identifiers. Specifically:

  1. They depend on different versions of loader-utils, and the default hash type changed from md5 to md4. We can work around this by explicitly specifying the hash type on our identifier template:

    Current:    "[path]___[name]__[local]___[hash:base64:5]"
    Workaround: "[path]___[name]__[local]___[md5:hash:base64:5]"
    
  2. They compose the core value of the hash in fundamentally different ways. The changes in question happened here: webpack-contrib/css-loader@d2f6bd2

    Working around this would require either:

    • Not using a hash in the identifier name (at least, although that still puts us on tenuous ground for other kinds of future changes).
    • Specifying a function for both babel-plugin-react-css-modules and css-loader instead of strings. This should be possible, but there’s an open issue about it not working right on babel-plugin-react-css-modules. Not sure whether that’s accurate or not.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions