Skip to content

Commit bb4b033

Browse files
fix: remove unscopable global warning (#1223)
* fix: remove unscopable global warning * remove FAQ entry * Apply suggestion from @teemingc --------- Co-authored-by: Tee Ming <chewteeming01@gmail.com>
1 parent 6969e81 commit bb4b033

File tree

3 files changed

+6
-56
lines changed

3 files changed

+6
-56
lines changed

.changeset/quiet-wings-learn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/vite-plugin-svelte': patch
3+
---
4+
5+
fix: remove unscopable global styles warning

docs/faq.md

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -54,34 +54,6 @@ Bad:
5454
<script type="text/typescript"></script>
5555
```
5656

57-
### Where should I put my global styles?
58-
59-
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.
60-
61-
Good:
62-
63-
```scss
64-
/* global.scss */
65-
html {
66-
color: $text-color;
67-
}
68-
```
69-
70-
```js
71-
// main.js
72-
import './global.scss';
73-
```
74-
75-
Bad:
76-
77-
```svelte
78-
<style lang="scss">
79-
:global(html) {
80-
color: $text-color;
81-
}
82-
</style>
83-
```
84-
8557
### Why can't `cssHash` be set in development mode?
8658

8759
`cssHash` is fixed in development for CSS HMR in Svelte components, ensuring that the hash value is stable based on the file name so that styles are only updated when changed.

packages/vite-plugin-svelte/src/utils/log.js

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,7 @@ export function logCompilerWarnings(svelteRequest, warnings, options) {
146146
let warn = isBuild ? warnBuild : warnDev;
147147
/** @type {import('svelte/compiler').Warning[]} */
148148
const handledByDefaultWarn = [];
149-
const notIgnored = warnings?.filter((w) => !ignoreCompilerWarning(w, isBuild, emitCss));
150-
const extra = buildExtraWarnings(warnings, isBuild);
151-
const allWarnings = [...notIgnored, ...extra];
149+
const allWarnings = warnings?.filter((w) => !ignoreCompilerWarning(w, isBuild, emitCss));
152150
if (sendViaWS) {
153151
const _warn = warn;
154152
/** @type {(w: import('svelte/compiler').Warning) => void} */
@@ -203,31 +201,6 @@ function isNoScopableElementWarning(warning) {
203201
return warning.code === 'css_unused_selector' && warning.message.includes('"*"');
204202
}
205203

206-
/**
207-
*
208-
* @param {import('svelte/compiler').Warning[]} warnings
209-
* @param {boolean} isBuild
210-
* @returns {import('svelte/compiler').Warning[]}
211-
*/
212-
function buildExtraWarnings(warnings, isBuild) {
213-
const extraWarnings = [];
214-
if (!isBuild) {
215-
const noScopableElementWarnings = warnings.filter((w) => isNoScopableElementWarning(w));
216-
if (noScopableElementWarnings.length > 0) {
217-
// in case there are multiple, use last one as that is the one caused by our *{} rule
218-
const noScopableElementWarning =
219-
noScopableElementWarnings[noScopableElementWarnings.length - 1];
220-
extraWarnings.push({
221-
...noScopableElementWarning,
222-
code: 'vite-plugin-svelte-css-no-scopable-elements',
223-
message:
224-
"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."
225-
});
226-
}
227-
}
228-
return extraWarnings;
229-
}
230-
231204
/**
232205
* @param {import('svelte/compiler').Warning} w
233206
*/

0 commit comments

Comments
 (0)