Skip to content

Compiler option to customize scoped class names #2822

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
mrkishi opened this issue May 19, 2019 · 2 comments
Closed

Compiler option to customize scoped class names #2822

mrkishi opened this issue May 19, 2019 · 2 comments

Comments

@mrkishi
Copy link
Member

mrkishi commented May 19, 2019

This is a feature brought up during the attribute to class name revamp for scoped styles. It seems forgotten, so I thought it'd be nice to have an issue for it.

Rich's comment:

I was thinking that as a follow-up to this PR, maybe it could be entirely user-configurable:

const counts = {};
const incr = id => {
  if (!counts[id]) counts[id] = 0;
  return counts[id] += 1;
};

const { code, css, map } = svelte.compile(source, {
  class: ({ name = 'svelte', filename, hash }) => `${name}-${incr(name)}`
});

That way we'd still get the correctness-guaranteeing behaviour (${name}-${hash}) out of the box, but it could be set up to use incrementing in situations where it makes sense to do so (e.g. there's no SSR, or the process is controlled a la Sapper), or if people were really byte-conscious they could do something like -${hash}. Perhaps that's too much boilerplate for common cases though.

I personally think it'd be a nice addition.

@Conduitry
Copy link
Member

Conduitry commented May 19, 2019

#570 looks like the issue where this has mostly been getting discussed before. Not that this should necessarily should be closed as a duplicate, as this is a more concrete suggestion about how this should behave. Maybe actually the other issue should be closed?

@mrkishi
Copy link
Member Author

mrkishi commented May 19, 2019

Oh, smh. I saw that one but didn't realize it was left open specifically for this...

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

No branches or pull requests

2 participants