Skip to content

Optional prefix #296

Answered by dcastil
dorshinar asked this question in Ideas
Aug 21, 2023 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Hey @dorshinar! 👋

You can do that already! It's not very pretty, but it does what you want:

const twMerge = extendTailwindMerge((config) => {
    Object.keys(config.classGroups).forEach((key) => {
        const value = config.classGroups[key]
        config.classGroups[key] = [...value, { tw: value, yo: value }]
    })

    return config
})

twMerge('tw-text-slate-100 yo-text-slate-100 text-slate-200')
// → 'text-slate-200'

But keep in mind that every prefix you use makes the internal data structure tailwind-merge computes exponentially bigger and might make the first call to twMerge slower (subsequent calls don't get slower). You can see in this line

config.classGroups[key] = [...value, { 

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dorshinar
Comment options

Answer selected by dorshinar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
context-v1 Related to tailwind-merge v1
2 participants