Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add @use in Sass files to load dependencies when tokens are split into several files #618

Closed
nhoizey opened this issue May 7, 2021 · 3 comments

Comments

@nhoizey
Copy link
Contributor

nhoizey commented May 7, 2021

Hello, I'm trying to use outputReferences: true for Sass targets while generating several files (mapping ouput to input), and I'm looking for advice about how to manage dependencies.

I would like to be able to have one single @use "tokens/components/button"; in a project button's Sass code, and not need to add multiple @use manually for all other tokens/**/*.scss Sass files this one depends on.

So I would like to have these @use — only the ones that are needed — automatically put into tokens/components/_button.scss at build time.

Is anyone already working like that, or having advice about how best to do it?

@dbanksdesign
Copy link
Member

A very small example of what you want to achieve in output files:

// tokens/component/button.scss
@use "tokens/color.scss";
$button-background-color: $color-background-primary;
// tokens/color.scss
$color-background-primary: #fff;

Correct?

I can kind of see how it could be done in a custom format... What you would do is in the custom format,

  1. Iterate over all tokens (should be filtered in the config by filePath so only button tokens are in a buttons.scss file)
  2. If the token has a reference, get the referenced token and that token should have a filePath attribute. Save that in an array to later build all the @use imports at the top of the file. You'll need to modify the filePath in a way that matches how you are building the other files
  3. Output each token as you normally would for SCSS

For the configuration you could follow the matching-build-files example to build files 1:1 with input files.

Does that make sense?

@nhoizey
Copy link
Contributor Author

nhoizey commented May 9, 2021

@dbanksdesign it makes perfect sense, I'll try to build it, thanks! 👍

@jorenbroekema
Copy link
Collaborator

Closing question issue, considered as answered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants