Sass has recently announced their new module system which needs to be used by @use and @forward.
My approach is the best way to use scss with Vite.
Use defineConfig to setup global scss (colors, mixin) and reuse in all components without import
css: {
preprocessorOptions: {
scss: {
additionalData: `@use "~/styles/main.scss" as *;`,
},
},
},
Here: Sandbox
Note: If you see the same CSS is being loaded multiple times.
When you use @use "~/styles/main.scss" as *;
equivalent import all styles to your file.
So, inside styles
folder must be stored variables, mixins and must use partial Sass files
If you want to style for common or reset, it must be put into src/index.scss
// Put in common css or reset css here.
:root {
--danger: #fe2c55;
--danger-dark: #d60032;
--danger-light: #ff5c83;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}