Skip to content
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

fix(web-fonts): hoist @import in single layer #2909

Merged
merged 8 commits into from
Jul 31, 2023
Merged

fix(web-fonts): hoist @import in single layer #2909

merged 8 commits into from
Jul 31, 2023

Conversation

zyyv
Copy link
Member

@zyyv zyyv commented Jul 24, 2023

When building with this warning, i think we can sort the css ahead of time.

// uno.config.ts
presetWebFonts({
  provider: 'google',
  fonts: {
    ...
  },
  inlineImports: false,
}),
image

@zyyv zyyv requested a review from antfu as a code owner July 24, 2023 14:09
@netlify
Copy link

netlify bot commented Jul 24, 2023

Deploy Preview for unocss ready!

Name Link
🔨 Latest commit bc8acf6
🔍 Latest deploy log https://app.netlify.com/sites/unocss/deploys/64c687c147bccc000874af52
😎 Deploy Preview https://deploy-preview-2909--unocss.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@zyyv zyyv marked this pull request as draft July 25, 2023 01:45
@zyyv
Copy link
Member Author

zyyv commented Jul 25, 2023

I don't know if it's better to handle it in core or vite plugin.
What do you think ? Or we don't need it at all.

@zyyv zyyv marked this pull request as ready for review July 25, 2023 08:02
@zyyv zyyv marked this pull request as draft July 26, 2023 15:11
@zyyv
Copy link
Member Author

zyyv commented Jul 27, 2023

Done.
Extracte css with @import preflight's and put it in a new layer named @imports.

@zyyv zyyv marked this pull request as ready for review July 27, 2023 14:14
@zyyv zyyv changed the title fix(core): sort @import on top of css fix(core): hoist @import in single layer Jul 27, 2023
Comment on lines 205 to 208
.map(async (i) => {
const css = await i.getCSS(preflightContext)
return css ? hoistAtImport(css) : undefined
}),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should put in the rule, not the core, as it, again, coupled and affect every generation

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean, when writing them, put them into the import layer actively?

prelights: [
 {
   layer: 'imports',
   getCSS: ()=> `@import ....`
 }
]

coupled and affect every generation

Although it is a bit coupled, uno can correct it in the final stage by Regexp, and extract the correct import css to the layer. Make it a default behavior? 😅

@antfu
Copy link
Member

antfu commented Jul 30, 2023

Pushed the changes. In some CSS parsers, @import can be everywhere. And when a rule emits a raw string, UnoCSS assumes the syntax error etc are handled correctly by the rule itself. To not baby-sitting too much is one of the factors that keep UnoCSS fast.

If the change looks good to you, we could merge it and proceed.

@antfu antfu changed the title fix(core): hoist @import in single layer fix(web-fonts): hoist @import in single layer Jul 30, 2023
@zyyv
Copy link
Member Author

zyyv commented Jul 31, 2023

To not baby-sitting too much is one of the factors that keep UnoCSS fast.

Thanks your guide, keep it in mind.🥰

@antfu antfu added this pull request to the merge queue Jul 31, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Jul 31, 2023
@antfu antfu added this pull request to the merge queue Jul 31, 2023
Merged via the queue into unocss:main with commit 9fc2851 Jul 31, 2023
9 checks passed
@zyyv zyyv deleted the fix/css/import branch August 19, 2023 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants