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 importing CSS packages in frontmatter #3537

Merged
merged 6 commits into from
Jun 6, 2022
Merged

Fix importing CSS packages in frontmatter #3537

merged 6 commits into from
Jun 6, 2022

Conversation

matthewp
Copy link
Contributor

@matthewp matthewp commented Jun 6, 2022

Changes

  • vite:css-post removes JS modules that only contain CSS. These modules only exist so that the CSS asset can be created. Vite removes them and updates import statements to also be removed.
  • However when you import a package the compiler creates a second import like import * as $$module from 'some/package'; which is used to discover if the package contains used web components. Because of these namespace imports, those don't get removed by vite:css-post.
  • The fix here is to create empty CSS chunks when import statements are left in.
  • Fixes 🐛 BUG: Importing @fontsource/* packages in Astro frontmatter results in a build erroring #3536

Testing

  • Test added specifically for @fontsource/* package since those are a bit popular.

Docs

N/A, bug fix.

@changeset-bot
Copy link

changeset-bot bot commented Jun 6, 2022

🦋 Changeset detected

Latest commit: 25d92eb

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

This PR includes changesets to release 1 package
Name Type
astro 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

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Jun 6, 2022
@matthewp matthewp marked this pull request as ready for review June 6, 2022 20:10
Copy link
Contributor

@tony-sull tony-sull left a comment

Choose a reason for hiding this comment

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

lgtm! Nice comments and test coverage

@matthewp matthewp merged commit 51c60de into main Jun 6, 2022
@matthewp matthewp deleted the fontsource-fix2 branch June 6, 2022 22:26
@github-actions github-actions bot mentioned this pull request Jun 6, 2022
@delucis delucis mentioned this pull request Jun 9, 2022
5 tasks
SiriousHunter pushed a commit to SiriousHunter/astro that referenced this pull request Feb 3, 2023
* Fix importing CSS packages in frontmatter

* Formatting

* Only update if the source code contains the import

* Consolidate the two plugins

* we do need a pre and a post

* Adds a changeset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 BUG: Importing @fontsource/* packages in Astro frontmatter results in a build erroring
2 participants