Is there a way to make Svelte use a method other than classes for scoping components? #15193
Unanswered
unikitty37
asked this question in
Q&A
Replies: 1 comment 3 replies
-
Try adding the // This is /svelte.config.js:
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
export default {
// Consult https://svelte.dev/docs#compile-time-svelte-preprocess
// for more information about preprocessors
preprocess: vitePreprocess(),
// v--------------- Add compiler options to add cssHash
compilerOptions: {
cssHash: () => '',
}
} This setting only works when you build the project. It doesn't work when running the development server ( |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Svelte adds a class with a hash to components in order to do scoping. This breaks Playwright's
toHaveClass
, which expects to match the whole classList, meaning that, instead ofI have to write
and, even then, I'm not 100% sure that regexp covers all cases, as it makes assumptions about the format of the scoping class, and that it will be at the end of the classList.
I could write a
hasScopedClass
assertion for Playwright, but I'm wondering if I can configure Svelte to scope its components a different way. Vue used av-<hash>
attribute and matched it in the CSS with[v-<hash>]
, which avoided this problem.I'm guessing Svelte does it this way for a reason (though I'd love to know what it is :) but it does make testing considerably more clunky. Is it possible to configure Svelte to do scoping without messing with the classList?
Beta Was this translation helpful? Give feedback.
All reactions