How to disable unused style warning in svelte
Asked Answered
B

2

6

I have a CSS rule which I used for global style, the style worked but my terminal keep show me this warning, how can I disable it?

src/components/Navbar.svelte changed. rebuilding...
• server
src/routes/index.svelte
Module Warning (from ./node_modules/svelte-loader-hot/index.js):
Unused CSS selector "*" (22:2)
20: 
21: <style global>
22:   * {
      ^
23:     font-family: 'Poppins';
24:   }
• client
src/routes/index.svelte
Module Warning (from ./node_modules/svelte-loader-hot/index.js):
Unused CSS selector "*" (22:2)
20: 
21: <style global>
22:   * {
      ^
23:     font-family: 'Poppins';
24:   }
✔ service worker (73ms)

Biquadratic answered 12/9, 2021 at 3:51 Comment(0)
T
4

Interesting but I can't find anything about the <style global> in the official documentation. Where did you see that this syntax is supported?

To fix that you can use the :global(*) modifier instead of just the * selector or move all global styles into a separated global.css file (useful to declare styles for *, body, a, ...). You can find a basic svelte project architecture in the official template and there is a /src/public/global.css file.

Turnip answered 12/9, 2021 at 7:46 Comment(3)
sorry man, honestly I don't remember why i wrote <style global>Biquadratic
@RobyCigar ahah in this case I guess it's just not svelte valid :)Turnip
@Turnip it is not part of Svelte but it is part of Svelte Preprocess github.com/sveltejs/svelte-preprocess#global-styleIllume
B
1

In rollup.config.js

export default {
    plugins: [
         svelte({
            onwarn: (warning, handler) => {
                const { code, frame, filename } = warning
                if (code === "css-unused-selector" && filename == 'src/routes/index.svelte') {
                    return;
                }
                handler(warning)
            },

         }),
      ]
    }

Barca answered 12/9, 2021 at 6:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.