-
-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not compatible with css-loader v4 #291
Comments
Here is my fork of the plugin, with fixed css-loader compatibility: |
@birdofpreyru why you didn't try to create PR for this fix? |
To move fast. It looks like the author does not maintain the package actively for a long time. I don't want to wait for review by the author, don't really want to discuss updates of dependencies I like to do, etc. Once I got it working, it took me no time to setup release as a separate package, and now if I need any other corrections I can do them fast. |
@gajus mind taking a look? This can be a whale of an issue to troubleshoot if one isn't aware of the changes OP mentions. And thank you for this awesome library! |
Pfew, lifesaver this one. Anyway, what are the plans to maintain that fork? Do you aim for it to replace this plugin at some point? |
@Hless do you ask me? I use my fork in my React projects, thus in the foreseen future I am planning to maintain it functional and up-to-date. At the same time, I don't have any issues with what it does and how it works, thus probably won't do with it anything beyond ocasional dependency updates when something breaks for me, or somebody asks for it. Everybody else following the thread: it is almost two months since the issue ticket was created, since no reply from the repo owner. I hope you see now my choice between fork and PR was very reasonable :) |
@birdofpreyru I suppose you're right about the fork, repo does not seem actively maintained anymore, thanks for your work. I decided to refactor my codebase not use the styleName prop anymore, but to refactor it to the standard import/className workflow. Webpack config is hard enough to maintain without having to rely upon plugins that are not actively maintained by a larger audience |
@Hless What is your plan regarding CSS class name scoping? From my seat, CSS modules worked fine for me for three years without any maintenance, thus it feels like spending a few days now to fix the compatibility with the latest PostCSS will make it a smooth ride for next few years. |
Well I did some digging and unless I'm mistaken the CSS module feature is part of css-loader now. So if you were to use react scripts you can see the documentation here: Since I'm using a custom webpack config, I configured it using css-loader directly:
(Note: this is the v4 syntax) Documentation on css-loader is here: I could be completely missing something here, as of now the only reason for using this babel plugin would be the |
It is a good point! I am also relying on this and another css-modules Babel plugins because in my setup I compile server-side version of code only with Babel, without Webpack; but your message makes me think that probably I should revisit how I do stuff, and indeed simplify it relying only on |
So I've spent a few days trying to figure this out. 😅 The problem is a change in I've opened an issue here: webpack-contrib/css-loader#1214 The tl;dr is that the PR changed |
Good job @benmvp , though it was figured out a while ago: webpack-contrib/css-loader#1152 and in the beginning of thread you have a link to my fork of the package which is patched to match the latest css-loader implementation, and also to rely on latest versions of all dependencies. |
Yeah @birdofpreyru I realized after doing the research and filing the bug that I should've just looked more closely at your fork to see what the problem was 🤦 Thanks for the links! |
The way I got around it was by importing loader-utils@2.0.0, and then adding this to my babel.config.js
|
Yeah, I saw that it takes a string or a function, so that's a nice fix! 👏 |
Ya, since I mainly copied code that already existed in these underlying libraries, it would be nice if they were exposed so we could just flag on which behavior we wanted |
@birdofpreyru - I've got a PR open (css-modules/generic-names#10) in Hopefully we can get that merged here, but at the very least it should make maintaining the fix easier in your fork. |
nice,hash has matched css-loader,thank you! |
@gajus could we please get an updated release that is compatible with the latest css-loader? :/ |
Switched to a fork for the babel css module transform since upstream is slow and not compatible with the latest css-loader anymore. See this issue for details: gajus/babel-plugin-react-css-modules#291
If someone raises a PR, I will happily review it and integrate it. |
Upgrade |
@gajus, @shallinta this isn't going to be as simple as Initially cloned, installed packages and then ran the tests. 8/29 failed Then I realized there is no Edit Read the whole thread and just dawned on me that @birdofpreyru also updated all the dependencies in his fork. If he would be kind enough to make a PR back here? For now I'm going to use his fork to keep the project I'm on moving. |
const genericNames = require('generic-names'); // v3.0.0
const CSS_MODULE_LOCAL_IDENT_NAME = '[local]___[hash:base64:5]';
// old: generateScopedName: CSS_MODULE_LOCAL_IDENT_NAME
generateScopedName: genericNames(CSS_MODULE_LOCAL_IDENT_NAME) |
Nice !!! |
with another hash conversion problem, try to pass
generateScopedName: genericNames(CSS_MODULE_LOCAL_IDENT_NAME, { context }) |
解决: webpack.config.js 配置如下: const genericNames = require('generic-names');
const generateScope = genericNames(localIdentName, {
context: process.cwd(),
});
const getStyleLoaders = (cssOptions, preProcessor = []) => {
const loaders = [
// require.resolve('style-loader'),
MiniCssExtractPlugin.loader,
// isProd ? MiniCssExtractPlugin.loader : require.resolve('style-loader'),
{
loader: require.resolve('css-loader'),
options: cssOptions,
},
];
if (preProcessor.length > 0) {
for (let item of preProcessor) {
loaders.push(require.resolve(item));
}
}
return loaders;
};
{
test: /\.scss$/,
exclude: /node_modules/,
include: path.resolve(__dirname, 'src'),
use: getStyleLoaders(
{
importLoaders: 1,
// modules: {
// localIdentName: '[name]__[local]_[hash:base64:5]',
// localIdentContext: path.resolve(__dirname, 'src'),
// },
modules: {
getLocalIdent({ resourcePath }, localIdentName, localName) {
return generateScope(localName, resourcePath);
},
},
},
['sass-loader']
),
}, babel.config.js 配置如下: const genericNames = require('generic-names'); // v3.0.0
// babel-plugin-react-css-modules
[
'react-css-modules',
{
generateScopedName: genericNames('[name]__[local]_[hash:base64:5]'),
filetypes: {
'.scss': {
syntax: 'postcss-scss',
},
},
exclude: 'node_modules',
},
], |
AFAIK this was always the case |
老哥 这个稳 |
It appears the new css-loader has changed their hash algorithm to use md4 instead of md5 (related to webpack/loader-utils#168 ), this means the hash generated by this babel plugin no longer matches what css-loader's hash is with no clear way around it
The text was updated successfully, but these errors were encountered: