Performance: Preprocessor support (SCSS, PostCSS)
This affects the CSS loading and rendering speed by changing how styles are processed and delivered to the browser.
<style lang="scss">
$primary-color: red;
.btn {
color: $primary-color;
font-weight: bold;
&:hover { color: blue; }
}
</style><style>
.btn { color: red; font-weight: bold; }
.btn:hover { color: blue; }
</style>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Plain CSS with repeated selectors | Minimal | Multiple if styles change dynamically | Higher due to larger CSS | [X] Bad |
| SCSS with variables and nesting | Minimal | Single or fewer reflows | Lower due to optimized CSS | [OK] Good |
lang="scss", which tells Svelte to preprocess styles with SCSS.lang attribute on the <style> tag to specify preprocessors.<style lang="postcss">. Other attributes like type or preprocess are not valid here.<style lang="scss">
$primary-color: #3498db;
.button {
color: $primary-color;
&:hover {
color: darken($primary-color, 10%);
}
}
</style>$primary-color is set to #3498db. The nested hover selector uses darken($primary-color, 10%).darken() function reduces brightness by 10%, so the hover color is a darker shade of #3498db.<style lang="scss">
$color: red
.button { color: $color; }
</style>$color: red is missing a semicolon at the end, which is required in SCSS.scss and postcss options in svelte.config.js. Adding multiple lang attributes or importing PostCSS in script won't work.Pass the test and this pattern moves unknown