michalkvasnicak / babel-plugin-css-modules-transform

Extract css class names from required css module files, so we can render it on server.
MIT License
326 stars 54 forks source link

dont work for css-loader@^2 #103

Closed VadimZvf closed 2 years ago

VadimZvf commented 5 years ago

classNames dont match with css-loader@2.0.0 or above with css-loader@1.0.1 all fine

felixcatto commented 4 years ago

With css-loader@3.6.0 all works fine I use generateScopedName: '[local]--[hash:base64:5]', in server babel config and localIdentName: '[local]--[hash:base64:5]', in client (webpack) config

felixcatto commented 4 years ago

It turns out, in some cases classNames really don't match. But you can generate them by yourself. someFIle.js

const crypto = require('crypto');

const generateScopedName = (localName, resourcePath) => {
  const getHash = value => crypto.createHash('sha256').update(value).digest('hex');
  const hash = getHash(`${resourcePath}${localName}`).slice(0, 5);
  return `${localName}__${hash}`;
};

server babel config

[
  'css-modules-transform',
  {
    generateScopedName,
    devMode: true,
  },
],

client webpack config

{
  loader: 'css-loader',
  options: {
    modules: {
      getLocalIdent: ({ resourcePath }, _, localName) => generateScopedName(localName, resourcePath),
    },
  },
},
suhanw commented 3 years ago

classNames don't match for me either, I'm using css-loader@5.0.1 and babel-plugin-css-modules-transform@1.6.2