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

Postcss @import glob support #12336

Open
4 tasks done
bluwy opened this issue Mar 8, 2023 · 7 comments
Open
4 tasks done

Postcss @import glob support #12336

bluwy opened this issue Mar 8, 2023 · 7 comments
Labels
feat: css p2-nice-to-have Not breaking anything but nice to have (priority)

Comments

@bluwy
Copy link
Member

bluwy commented Mar 8, 2023

Description

Vite currently uses postcss-import to resolve @import, there are some postcss plugins out there that supports glob imports like:

But they can't be used as they can't be injected before Vite's postcss-import plugin instance. Vite also adds it's custom resolve logic (alias, extension, export conditions, etc), so postcss-import can't be swapped out.

Suggested solution

Ideally a first-class support would prevent needing a new API for injecting plugins before postcss-import.

It could look like postcss-import-ext-glob using @import-glob, as it's also a suggested plugin in postcss-import's readme.

Alternative

No glob support. Or support injecting plugins before postcss-import.

Additional context

No response

Validations

@sun0day
Copy link
Member

sun0day commented Mar 10, 2023

I think we could internally support the @import glob pattern via postcss-easy-import. Then we can consider adding new APIs to inject postcss plugins like postcss-import-ext-glob before postcss-import.

@bluwy
Copy link
Member Author

bluwy commented Mar 12, 2023

Since @import with globs isn't part of the spec, I think we should introduce a new API if we want to support this, and @import-glob might be the best choice. Though since Vite had never introduced special APIs in CSS files, this might need a bit of discussion before landing.

@sapphi-red
Copy link
Member

related: #10079

@bluwy
Copy link
Member Author

bluwy commented Mar 15, 2023

Interesting, maybe rewriting the plugin with Postcss 8's plugin would solve this issue, so we don't have to carve out an API to put plugins before Vite's (which I'm not sure how without non-standard plugin properties). I guess one upside of having this builtin is support for globbing with aliases 🤔

@ashutosh887
Copy link

@bluwy I would like to work on this issue
Please assign me

@Farnsi
Copy link

Farnsi commented Mar 19, 2023

What about @use and @forward and resolve aliases?

@Larzans
Copy link

Larzans commented Mar 27, 2023

in the meantime you can use import.meta.glob in your main.js file to include all the css files of a folder as suggested here #6688 (comment) by Knovour

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: css p2-nice-to-have Not breaking anything but nice to have (priority)
Projects
Status: Discussing
Development

No branches or pull requests

7 participants