Skip to content

feat: support import assertions#8937

Merged
patak-cat merged 1 commit intovitejs:mainfrom
bluwy:feat-support-import-assertions
Jul 5, 2022
Merged

feat: support import assertions#8937
patak-cat merged 1 commit intovitejs:mainfrom
bluwy:feat-support-import-assertions

Conversation

@bluwy
Copy link
Member

@bluwy bluwy commented Jul 5, 2022

Description

Fix #4934

This basically strips off the import assertion part as Vite already handles it.

It's still a stage 3 feature, but esbuild, rollup, and other tools all already support it. Using import assertions in deps works today.

Additional context

I see some downsides if we don't strip it, and instead let browsers handle natively:

  1. Browser support isn't great yet
  2. We can't detect if a JSON import is using import assertions or not, so we have to mark it with a query, making the process a bit complex
  3. Native JSON import does not support named imports. It might be confusing that it doesn't work by default in Vite.

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@netlify
Copy link

netlify bot commented Jul 5, 2022

Deploy Preview for vite-docs-main ready!

Name Link
🔨 Latest commit a397579
🔍 Latest deploy log https://app.netlify.com/sites/vite-docs-main/deploys/62c46e7fc713290008e1a0bc
😎 Deploy Preview https://deploy-preview-8937--vite-docs-main.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 settings.

@bluwy bluwy added the p3-significant High priority enhancement (priority) label Jul 5, 2022
@bluwy bluwy mentioned this pull request Jul 5, 2022
Copy link
Member

@patak-cat patak-cat left a comment

Choose a reason for hiding this comment

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

Sweet! I agree that this is a good step forward. We may want later to document this, and once the support is more extended re-evaluate what is the best to avoid stripping them.

@patak-cat patak-cat merged commit 2390422 into vitejs:main Jul 5, 2022
@bluwy bluwy deleted the feat-support-import-assertions branch July 5, 2022 18:37
@ben ben mentioned this pull request Jul 9, 2022
36 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p3-significant High priority enhancement (priority)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Import Assertions

2 participants