johanholmerin / style9

CSS-in-JS compiler inspired by Meta's stylex
MIT License
570 stars 27 forks source link

perf: vite plugin process css logic #95

Closed nonzzz closed 7 months ago

nonzzz commented 1 year ago

Linked Issues

94

Description

This pull request won't need option fileName. Perf renderChunk logic so that it can work better with vite.

wmertens commented 1 year ago

BTW, I think we can speed up processing a little bit by checking if the code contains style9 before running babel on it

nonzzz commented 1 year ago

@wmertens I don't understand you mean. Should we need check it in transform?

wmertens commented 1 year ago

Yes correct, if style9 isn't mentioned there's no point in generating an AST

nonzzz commented 1 year ago

OK. I will try it

wmertens commented 1 year ago

And for the css plugin, maybe it's better to throw if the plugin isn't there?

nonzzz commented 1 year ago

@wmertens No. vite already includes these 2 plugins. This is also done in other similar libraries

wmertens commented 1 year ago

What I'm worried about is that the plugin only works if those two plugins are present, so IMHO either it should throw or it shouldn't test for them

nonzzz commented 1 year ago

Qwik is base on vite and vite contains vite:css and vite:css-post plugin. I will test Qwik in my local env.

nonzzz commented 1 year ago

You can look at vite-css and vite-plugin If vite don't provide those plugin will panic

wmertens commented 1 year ago

@nonzzz when I add this as the first line of transformStyle9:

  if (!/style9/.test(code)) return;

then the time spent goes from: Screenshot from 2023-05-15 09-04-16

to: image

nonzzz commented 1 year ago

@nonzzz when I add this as the first line of transformStyle9:

  if (!/style9/.test(code)) return;

then the time spent goes from: Screenshot from 2023-05-15 09-04-16

to: image

cool.

wmertens commented 1 year ago

I can confirm that this change fixes the extra CSS file in Qwik for building, yey :-)

In dev mode the style doesn't work, even after changing the file (which used to work because the hot reload had the correct css module path). Trying to find out why - it looks to be reloading the page instead of hot reloading.

I'm pretty sure this is a problem with Qwik though, so it shouldn't block this PR. Changing the ordering doesn't make a difference.