Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force add styles to svelte in scss

I'm trying to add some CSS which will be detected as unused CSS.

There's a workaround that we can use :global(.class) {} to do it.

But this can only add styles. How can we add nested scss class instead?

I want to use something like

<style lang="scss">
    div:global(.marked) {
        a,
        a:visited {
            color: #3498db;
        }

        a:hover,
        a:focus,
        a:active {
            color: #2980b9;
        }

        pre {
            background-color: #fafafa;
            padding: 1rem;
            text-align: left;
        }
    }
</style>

or

<style lang="scss">
  div:global(.marked) {
    @import './theCss.scss';
  }
</style>

But seems Svelte will transform it into lots of pure CSS and turn out will be unused CSS again.

Unused CSS selector "div:global(.marked) a"svelte(css-unused-selector)
Unused CSS selector "div:global(.marked) a:visited"svelte(css-unused-selector)
Unused CSS selector "div:global(.marked) a:hover"svelte(css-unused-selector)
Unused CSS selector "div:global(.marked) a:focus"svelte(css-unused-selector)
Unused CSS selector "div:global(.marked) a:active"svelte(css-unused-selector)
Unused CSS selector "div:global(.marked) pre"svelte(css-unused-selector)

enter image description here

Is there any good solution for this?

like image 695
Ignacio Lee Avatar asked Dec 20 '25 14:12

Ignacio Lee


1 Answers

With SCSS and Svelte can't you do it like so:

div {
  &:global(.marked){
    //put your style in here
  }
}

Because I believe you would still be able to access the main div style and add specific style for when it is marked.

Hope that helps

like image 149
Eli-ott Avatar answered Dec 23 '25 04:12

Eli-ott