Why CSS from externals packages is appended to my CSS bundle? #1414
Replies: 2 comments 3 replies
-
We've documented We haven't done this for the webpack plugin though, and it's not exactly the same as the I'm a bit confused as to what you expect the outcome to be. Are you using CSS variables from a separate package, but don't want them to be included in the CSS bundle? Or do you not expect CSS variables defined with Vanilla Extract to be included in the CSS bundle? |
Beta Was this translation helpful? Give feedback.
-
@askoufis sorry for the delay. I'll try to be clearer about the use case. In my project, I import a specific token from this external package. At build time, vanilla will build the tokens for my actual package which is perfect. However, I don't need vanilla to output the css from this external. Because it's an external, somebody else in my design care about adding the css of this external to the dom. So, when calling appendCss, there is no reason to append CSS that comes from an external package. Am I clear? Do you see a use case where we will want to ouput CSS of a webpack external? I would propose 3 options:
I understand the solution you proposed, I can add an additional build to the external package so it will expose all the tokens directly from JS but I would want to avoid to have another build to maintain particularly if it makes sense to not appending external CSS. Do you need more details about the use case or it's clear enough? |
Beta Was this translation helpful? Give feedback.
-
Hi,
The vanilla extract plugin includes an externals option.
Where can we find documentation about this feature? I'm trying to understand its exact functionality.
Specifically, when I define a package as "external", I expect the CSS variables from this package not to be included in my CSS bundle. However, this doesn't seem to be the case.
From my understanding, defining a package as "external" should signal to Webpack to exclude all exposed content from this package in the bundle.
However, it appears that the
externals
option only affects JavaScript files and does not consider CSS. Could you provide some clarification on this behavior and how we can achieve the desired outcome for CSS?I played with it locally and I get it work by enriching the filter in the
appendCss
function of the css adapter:vanilla-extract/packages/integration/src/processVanillaFile.ts
Lines 82 to 91 in e7d79f2
Something like:
Maybe we can change the
outputCss
option to possibly be a function that receives the actual fileScope and return a boolean? If it's ok for you, can I send a PR? It will help me a lot to decrease CSS bundle size.Something like:
My use case is that I have a page with multiple CSS bundle. Each CSS bundle uses CSS from some "external" package.
Beta Was this translation helpful? Give feedback.
All reactions