You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
will generate such CSS: .block.svelte-3zrlxr{display:block}
.block is my own custom class name
.svelte-3zrlxr is auto-generated class name for whole component
But this is not enough!
This was a "cheap" solution, that have side effects!
Today... custom class names (like block) can collide with GLOBAL class names.
This means, that custom used classes are simple not isolated!
Describe the proposed solution
Svelte like solution. Example code:
(module was added to not break compatibility)
Here is one little problem:
svelte-preprocess-cssmodules
requires "svelte": "^3.22.3"
(updated 1 year ago)
so I get errors:
Could not resolve dependency:
npm ERR! peer svelte@"^3.20.0" from [email protected]
npm ERR! node_modules/svelte-preprocess-cssmodules
npm ERR! svelte-preprocess-cssmodules@"^2.2.4" from the root project
I used --force to install
Not sure if this needs to be added in svelte directly
I'm not sure either... But css scoping is not perfect at the moment.
svelte-preprocess-cssmodules
has bind() and allows following awesome Code:
<script>
let color = 'red';
</script>
<p class="text">My lorem ipsum text</p>
<style module>
.text {
font-size: 18px;
font-weight: bold;
color: bind(color);
}
</style>
hmm that's odd. You might want to file an issue on the svelte-preprocess-cssmodules repo. I do have some trouble getting it to work in a test project myself... Anyways, I believe this issue is a duplicate of #6972 and should be closed.
Describe the problem
First... Vue has this functionality - I miss in Svelte
https://vuejs.org/api/sfc-css-features.html#css-modules
vitejs/vite#7447 (comment)
Code like this in Svelte:
will generate such CSS:
.block.svelte-3zrlxr{display:block}
.block is my own custom class name
.svelte-3zrlxr is auto-generated class name for whole component
But this is not enough!
This was a "cheap" solution, that have side effects!
Today... custom class names (like block) can collide with GLOBAL class names.
This means, that custom used classes are simple not isolated!
Describe the proposed solution
Svelte like solution. Example code:
(module was added to not break compatibility)
or convert (auto obfuscate)
Both should be possible
Alternatives considered
CSS-modules work today. They obfuscate class names.
Vite support CSS modules: https://vitejs.dev/guide/features#css-modules
If i write code like this, it works:
It generate this class name for "block":
_block_1xra7_1
But now, I need to split component in separate files.
I search a way to use <style> block in Svelte file and not an external module.css
Importance
would make my life easier
The text was updated successfully, but these errors were encountered: