Skip to content

How to share variables between JS and SCSS? #9601

Answered by amcsi
amcsi asked this question in Q&A
Discussion options

You must be logged in to vote

I found the solution 🚀

I realized that the same thing I did for a Laravel Mix 5->6 upgrade worked for Vite too, as per this Github comment of mine.

The gist of it is: _foo.scss (with the exported variables) should be renamed to foo.module.scss, and rather than doing a destructured import of the variables from the scss file, the entire default needs to be imported, and then that can be const destructured.

So rather than doing:

import { primary } from './foo.module.scss';

You would need to do this instead:

import foo from './foo.module.scss';
const { primary } = foo;

Replies: 5 comments 15 replies

Comment options

You must be logged in to vote
6 replies
@kachmul2004
Comment options

@Erol314
Comment options

@Roberto-Stanley
Comment options

@Sfolkerts89
Comment options

@UBlaster
Comment options

Answer selected by amcsi
Comment options

You must be logged in to vote
7 replies
@amcsi
Comment options

@tvld
Comment options

@amcsi
Comment options

@stephanfriedrich
Comment options

@SageJustus
Comment options

Comment options

You must be logged in to vote
2 replies
@rthoreau
Comment options

@Sfolkerts89
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet