How to globally inject SCSS variables now that Sass has deprecated @import? #18388
Replies: 2 comments 3 replies
-
I managed to get something working, but I can't say I love it. Vue componentsVue components can inherit Sass variables from the vite: {
css: {
preprocessorOptions: {
scss: {
api: 'modern-compiler',
additionalData: `
@use "sass:color";
// Add to the global Sass namespace
@use "my-package/tokens/scss/variables" as *;
`,
},
},
},
} Sass filesSeparate usage within // _layout.scss partial
@use "my-package/tokens/scss/variables" as *;
body {
color: $my-var;
} // app.scss
@use "layout"; |
Beta Was this translation helpful? Give feedback.
-
Not sure if this thread is appropriate for my question, but similar to you, I'm trying to import global scss files that contain rules/properties and not just variables (or mixins or functions). Edit: I've figured it out. You can import an SCSS file in main.ts like import '@/main.scss' |
Beta Was this translation helpful? Give feedback.
-
How would you inject global SCSS variables into all Vue components, non-namespaced, in a project that utilizes Vite?
I have some SCSS variables that I would like to be available in all my Vue components within the project, as well as available in any
**/*.scss
files in the same project.The official docs recommend recommend utilizing
additionalData
as shown below, although doing so with the new@import -> @use
change doesn't seem to work.What I have below works if you change
@use
to@import
just fine, but not as-is.I started a related discussion in the sass repository in an issue that was already open (they don't really seem concerned with the Vite ecosystem or the repercussions of deprecating the existing
@import
functionality).Beta Was this translation helpful? Give feedback.
All reactions