vanilla-extract icon indicating copy to clipboard operation
vanilla-extract copied to clipboard

feat: integration callbacks

Open astahmer opened this issue 2 years ago • 6 comments
trafficstars

hey, I made a vite plugin that allows purging any unused style generated by vanilla-extract/sprinkles

https://twitter.com/astahmer_dev/status/1601244606133567488

it needs some minor changes (mostly onEvaluated+serializeVanillaModule callbacks for the integration package + forceEmitCssInSsrBuild option for the vite plugin)

this PR adds:

  • a onEvaluated callback to packages/integration/src/processVanillaFile.ts (very similar to what was proposed here)
  • a serializeVanillaModule callback to packages/integration/src/processVanillaFile.ts, pretty much like the current serializeVirtualCssPath callback, it allows customizing the behaviour
  • integrates the HMR fix from this PR
  • exports the default implementation of serializeVanillaModule
  • makes changes to the plugins integration (vite/webpack/esbuild/rollup) by allowing to pass those new callbacks to the processVanillaFile call
  • exports the ProcessVanillaFileOptions & SprinklesProperties type
  • creates an AdapterContext (which is just a reference to the result of the adapter after the evalCode of processVanillaFile so anyone can retrieve the generated class names / CSS rules by file scopes
  • allows customizing the forceEmitCssInSsrBuild option for the vite plugin (needed to make the HMR work with vite-plugin-ssr), would probably allow removing the hard-coded checks (['astro:build', 'solid-start-server', 'vite-plugin-qwik'].includes())
  • fix: using raw .css.ts from another package than config.root (monorepo/linked dependencies)
  • fix: perf improvement by removing a big regex, especially when used on node_modules filePath

let me know if there's any questions or things you'd like to see

astahmer avatar Dec 09 '22 16:12 astahmer

🦋 Changeset detected

Latest commit: dab0f257c10cdf3aec9a220dbf6191281ada0831

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@vanilla-extract/esbuild-plugin Minor
@vanilla-extract/rollup-plugin Minor
@vanilla-extract/sprinkles Minor
@vanilla-extract/vite-plugin Minor
@vanilla-extract/css Patch
@vanilla-extract/integration Minor
@fixtures/sprinkles Patch
@fixtures/features Patch
@fixtures/low-level Patch
@fixtures/recipes Patch
@fixtures/themed Patch
@fixtures/unused-modules Patch
vanilla-extract-example-webpack-react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

changeset-bot[bot] avatar Dec 09 '22 16:12 changeset-bot[bot]

You should add a changeset, it will likely be brought up when maintainers get to this so having it done beforehand is best.

endigma avatar Dec 21 '22 14:12 endigma

news about this ?

tbrowang avatar Mar 19 '23 01:03 tbrowang

news about this ?

hey ! i'll try to summarize from my side:

  • I gave up this approach because of the current VE limitations / lack of news from maintainers so I ended up removing the code related to that PR from my repo
  • then I went with another approach, named vanilla-wind, (here in the code), details on twitter here, where I'd basically use VE (only the core, I kind of made my own sprinkles) internally but didnt require it explicitly, meaning: no .css.ts limitations, still fully compile-time (even more since I only generate the used styles), still typesafe, with arbitrary values, nested conditions & dynamically applicable selectors

but that approach still relied on tranforming the src code to replace it with the generated class names, meaning an extra integration should be made in each bundler (vite, esbuild, webpack, etc etc). I thought of unplugin but it doesn't support everything yet, ex: nested plugins (which I relied upon a lot)

still, even though it was a nice PoC of the static extraction box-extractor could provide, it was kind of buggy and I was getting bored of spending most of my time trying to fix HMR on every env possible: client rendering, SSR and 0 JS on different frameworks (just vite, vite-plugin-ssr, rakkas.. and this was only using vite, now imagine if I had to do that with webpack etc..) rather than working on the actual features.. generally having transforms makes HMR quite hard to get right (caching/invalidating/reloading which modules..)

then I received a message from a maintainer of well-known organization and I've been working these past weeks on a similar solution than vanilla-wind, which I'll deprecate/remove once the new project gets publicly released

tl;dr: I think it still could be of use to some people but not to me at this point so feel free to close this PR

astahmer avatar Mar 20 '23 09:03 astahmer

Sad ending then. No progress towards the optimized version of vanilla extract where unused styles aren't a thing anymore.

Thank you for the updates, I hope maintainers are OK since they do not respond much :| .

Can't wait to test your vanilla-wind v2.

neolectron avatar Mar 21 '23 04:03 neolectron

FWIW, Panda CSS is the new project that I was working on and that became public in the last days

astahmer avatar Jun 19 '23 13:06 astahmer