-
Notifications
You must be signed in to change notification settings - Fork 29
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
Multiple output files / omitting tokens from output in specific plugins #250
Comments
Yeah there are a few layers going on here! Appreciate you explaining the whole situation. Usually, yes, it is an antipattern to manually-edit generated files. However, if the tokens/output don’t change often it can be workable enough. I’ll start by explaining some assumptions Cobalt makes (that may or may not hold true), and then suggest some possible solutions. Cobalt assumes you have design token documentation and that it lists the global IDs for those tokens. That’s why the Sass API and JS API look the same with But rather than just treating the generated
So all that said, I am hesitant to split the output into multiple files, because as you pointed out the difficulty of using And also I agree solving #212 is worthwhile—it seems useful to otherwise “ignore” certain tokens from output based on the plugin (granted that many tools can remove unused stuff in the end). Which could also help. |
Hey Drew, It would be really nice, if we can describe, in which file those tokens are being saved. e.g.
I've added filename: "light.css" and "$filename": "component.css", If something like this would be possible, it would be awesome :) |
Short answer: This is something Cobalt 2.0 (“Terrazzo”) will make easier to do, even if that means writing partial plugins to accomplish this. There may not be an explicit option/docs for this, but it’ll be way easier to pull off than the “hack” of loading the CSS plugin multiple times. Longer answerThis is something I don’t think we’ll support an official option / docs for because it can impose a few difficulties. While I do agree with your proposal of this living in the config file, not It could break some modes. The way the CSS cascade works, order of appearance is the “tiebreaker” for specificity. In the scenario you’re “bundling” or loading multiple files, it becomes more difficult to guarantee they’re loaded in a specific order (not unless you’re manually writing the HTML yourself). Even if your tokens don’t have this issue, there could be a scenario where some tokens expect one mode to load before the other, and now there’s a brittle requirement their tooling has to load files in a specific order (which may be beyond their ability to control). So this could introduce some bugs whereas a single file will always load CSS predictably, for all possible setups, 100% of the time. It encourages a bit of an anti-pattern in editing generated code. Cobalt is categorized as a codegen tool that generates code that shouldn’t be modified directly (it’s why there are “do not edit” notices at the top of each file). Imposing organizational restrictions on generated code often creates unnecessary work for unknown benefit—why require the tool to organize code in a certain way if the final result is the same? Of course, as the arbiter of your stack it’s your decision to do this! But also just as OSS this can expand the support surface area / introduce bugs into a project that make it more difficult for maintainers to manage when this doesn’t solve a common problem many users have and is more of an opinionated thing. Hope that makes sense! Again, not a “Cobalt won’t support this” answer; just more of a nuanced “there are ways to accomplish this in Cobalt but not using encouraged happy paths” (and there probably won’t be docs on this) |
This may be related to #212...
We're currently using Cobalt with plugin-css and plugin-sass in CSS variable mode, resulting in one css and one scss file with everything we need.
However, our developers brought up that they currently manually split the one css file into multiple files/folders - so as to better organize the token types and levels and make it more maintainable/readable. As for the SCSS, it so happens that they only really need the token functions and typography mixins, so to minimize the code, they manually get rid of the rest of the SCSS output.
My goal is to automate the design token stack as much as possible, so I'm not the biggest fan of them manually intervening. However I do unterstand where they are coming from and have been wondering if Cobalt could provide such functionality in a future version.
One way to solve this would be to provide information in each tokens $extensions on where and if to output the resulting CSS, SCSS or JS. But I'm not sure that would be the smartest approach, since you'd have to specify such information for each plugin... And it would also be problematic if alias targets are specified to be ignored while being pointed to elsewhere.
So this is more an invitation for discussion than a suggestion I guess. :) Any thoughts? Thank you!
The text was updated successfully, but these errors were encountered: