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
Copy file name to clipboardExpand all lines: docs/faq.md
+28Lines changed: 28 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -45,6 +45,34 @@ Bad:
45
45
<scripttype="text/typescript"></script>
46
46
```
47
47
48
+
### Where should I put my global styles?
49
+
50
+
Global styles should always be placed in their own stylesheet files whenever possible, and not in a Svelte component's `<style>` tag. The stylesheet files can then be imported directly in JS and take advantage of Vite's own style processing. It would also significantly improve the dev server startup time.
51
+
52
+
Good:
53
+
54
+
```scss
55
+
/* global.scss */
56
+
html {
57
+
color: $text-color;
58
+
}
59
+
```
60
+
61
+
```js
62
+
// main.js
63
+
import'./global.scss';
64
+
```
65
+
66
+
Bad:
67
+
68
+
```svelte
69
+
<style lang="scss">
70
+
:global(html) {
71
+
color: $text-color;
72
+
}
73
+
</style>
74
+
```
75
+
48
76
### How do I add a Svelte preprocessor from a Vite plugin?
49
77
50
78
If you are building a Vite plugin that transforms CSS or JS, you can add a `api.sveltePreprocess: PreprocessorGroup` to your Vite plugin definition and it will be added to the list of Svelte preprocessors used at runtime.
message: `No scopable elements found in template. If you're using global styles in the style tag, you should move it into an external stylesheet file and import it in JS. See https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#where-should-i-put-my-global-styles.`
0 commit comments