-
-
Notifications
You must be signed in to change notification settings - Fork 608
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
getLocalIdent
function no longer falls back to default implementation
#1191
Comments
It is breaking change |
Do not use |
I did not include the entire function, as to not bloat the issue report. I will say that I do need custom behavior in certain cases, for certain imports, but not always. Can you provide a work around so that I could still access the default Alternatively, could having the custom implementation return an empty string be considered for triggering the old behavior that was lost? |
No alternatives you should use own function or don't use the |
If you found place where the default function doesn't generate valid CSS classname, please report about it and we will fix it |
Nope, that wasn't the case. In this case, we converted an internal library that previously bundled its CSS with very specific class selector names to start shipping that library as a "loose" library, with unbundled CSS files. To provide more details, we were using the I think we could accomplish the same behavior with additional rules in the webpack config, it was just very convenient to bundle all that logic into one rule. Anyway, thanks for the additional details. |
@tvsbrent What is real use case? Why you need so complex logic? |
We have 2 internal libraries that we consume in our frontend applications. One is a design system library, consisting of styled buttons and components like that. The other is a business-logic component library, one that has components most FE applications need, consisting of components like the user settings menu, log out, things like that. Previously, we would bundle all the code and css up and have a consuming project use those bundles. In the bundled CSS we would add a very specific prefix to the selectors to namespace them. So Recently, we introduced tree shaking, so we started shipping unbundled sources in the packages. So now the consuming app is bundling all the CSS and generating the class selector names in its build. To preserve that old behavior of prefixing the design-system / business-logic library class selectors, we provide some Webpack config and utility functions. One such utility function was a custom const getLocalIdent = (context, localIdentName, localName) => {
if (shouldProcessAsDesignSystem(context.resourcePath)) {
if (context.resourcePath.includes('base.css')) {
// If using DS as a source library, we need to mangle the base.css names for backward compatibility
if (sourceLibraries.includes('design-system')) {
return `design-system-${localName}`;
}
// If using the packaged version, the names are already mangled appropriately
return false;
}
// All other DS CSS uses this pattern
return `design-system-${path.parse(context.resourcePath).name}-${localName}`;
}
if (shouldProcessAsBusinessLogic(context.resourcePath)) {
return `business-logic-${path.parse(context.resourcePath).name}-${localName}`;
}
return false;
}; As you can see, we were using the I can't say this is the most awesome thing we've ever done, but sometimes you go to production with the code you have! ;) |
hm, okay, let's mark it as features, feel free to send a PR |
Just interesting case what we should do with |
Fixed, release will be in near future, we wait PostCSS 8 bugfix with |
Expected Behavior
A
getLocalIdent
function that return a falsy value should fallback to thedefaultGetLocalIdent
function found in theutils.js
.Actual Behavior
With the 4.x release of
css-loader
, the behavior introduced in this pull request no longer works. A customgetLocalIdent
function can no longer return a falsy value and have the defaultgetLocalIdent
function invoked.I couldn't see any other convenient work arounds, like being able to import that default function and invoking it myself in my custom function.
Code
How Do We Reproduce?
Have a
getLocalIdent
function return a falsy value.The text was updated successfully, but these errors were encountered: