Skip to content

Compiler option to customize scoped class names #2822

@mrkishi

Description

@mrkishi

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions