style9 icon indicating copy to clipboard operation
style9 copied to clipboard

perf: vite plugin process css logic

Open nonzzz opened this issue 2 years ago • 12 comments

Linked Issues

#94

Description

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

nonzzz avatar May 14 '23 05:05 nonzzz

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

wmertens avatar May 14 '23 16:05 wmertens

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

nonzzz avatar May 14 '23 16:05 nonzzz

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

wmertens avatar May 14 '23 18:05 wmertens

OK. I will try it

nonzzz avatar May 14 '23 18:05 nonzzz

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

wmertens avatar May 14 '23 18:05 wmertens

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

nonzzz avatar May 14 '23 18:05 nonzzz

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

wmertens avatar May 14 '23 18:05 wmertens

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

nonzzz avatar May 14 '23 18:05 nonzzz

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

nonzzz avatar May 14 '23 18:05 nonzzz

@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

wmertens avatar May 15 '23 07:05 wmertens

@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.

nonzzz avatar May 15 '23 08:05 nonzzz

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.

wmertens avatar May 15 '23 10:05 wmertens