Skip to content

Support for getLocalIdent #6

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

Closed
mvrlin opened this issue Sep 19, 2020 · 5 comments · Fixed by #7
Closed

Support for getLocalIdent #6

mvrlin opened this issue Sep 19, 2020 · 5 comments · Fixed by #7

Comments

@mvrlin
Copy link

mvrlin commented Sep 19, 2020

Hello! I really enjoy using your preprocess, but I need a way to generate custom class names, that are not based on the default localIdentName. Webpack css-loader has a getLocalIdent function option for that.

@micantoine
Copy link
Owner

Hi @mvrlin , if the default localIdentName option is the issue you can easily change it with any other available token or custom strings of your choice.

if you want to generate the classname with your own rules without going through the default interpolateName() function, what kind of information would you need ?

I checked what css-loader is doing with getLocalIndent providing the following data:

  • The loaderContext object
  • The localIdentName rule string
  • The localName (the css className)
  • and some extra info in options

I could provide the same type of info with additional data if necessary

function getlocalIndent(
  context: {
    context,
    resourcePath,
  },
  // instead of the rule string  only
  localIndentName: {
    rule, // the rule string
    generated, // the generated classname which you could hook into 
 },
  localName, // the css className string
  options: {
    markup, // the markup content
    styles, // the styles content
  }, 
) {}

something like this would be then possible

...
use: [
  {
    loader: 'svelte-loader',
    options: {
      preprocess: [
        cssModules({
          localIndentName: '[hash:base64:10]',
          getLocalIndent: (context, localIndentName, localName, options) => {
            return localIndentName.generated.toLowerCase();
          }
        }),
      ]
    }
  }
]
...

what do you think?

@mvrlin
Copy link
Author

mvrlin commented Sep 20, 2020

@micantoine I want to generate very short class names like .a-a, .a-b, etc. It would be awesome, if you will provide the option you described above. Also, it'll be very nice, if you can add support for Rollup & WebPack 😊.

@micantoine micantoine linked a pull request Sep 21, 2020 that will close this issue
@micantoine
Copy link
Owner

@mvrlin Check the linked pull request, I have renamed some parameters that I think would make more sense.
If it's all good, let's merge it and publish a new version

@mvrlin
Copy link
Author

mvrlin commented Sep 21, 2020

@micantoine Looking good! What do you think about TypeScript typings?

@micantoine
Copy link
Owner

micantoine commented Sep 22, 2020

@mvrlin I do like Typescript, could be nice to develop the preprocess with it. At the time of making it, it was just a small js file I used on my personal projects which I thought could benefit others encountering the same issue with the native scoped system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants