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

feat: rework dynamic-import-vars #7756

Merged
merged 36 commits into from
May 10, 2022
Merged

Conversation

poyoho
Copy link
Member

@poyoho poyoho commented Apr 15, 2022

Description

fix: #6992

Additional context

I think we can deps on @rollup/dynamic-import-vars (dynamicImportToGlob) to re-implement it.

We can get some enhancements to dynamic import

  • replace translater to es-module-lexer instead of compiler. There should be an improvement in performance?
  • support dynamic import query syntax. such as ?raw.
  • support @/${variable} resolve path.

Because we can make dynamic import use the code of import.meta.glob 🤔


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.n
  • 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.

@poyoho poyoho added the enhancement New feature or request label Apr 15, 2022
@poyoho poyoho marked this pull request as draft April 15, 2022 15:48
@poyoho poyoho marked this pull request as ready for review April 19, 2022 14:49
@patak-dev patak-dev added this to the 3.0 milestone Apr 24, 2022
@caoxiemeihao
Copy link
Contributor

Hey! 👋
It looks so cool!

@patak-dev patak-dev added the p3-minor-bug An edge case that only affects very specific usage (priority) label May 5, 2022
@antfu
Copy link
Member

antfu commented May 8, 2022

#7537 got merged. While I do not completely understand this PR, from a brief overview, I guess maybe instead of depending on the glob transform directly, maybe we could directly transform the code to import.meta.glob expressions and let the importMetaGlob plugin handle the rest. Similiar to

s.overwrite(
index,
index + exp.length,
`new URL((import.meta.glob(${pattern}, { eager: true, import: 'default' }))[${rawUrl}], self.location)`,
{ contentOnly: true }
)

@poyoho
Copy link
Member Author

poyoho commented May 9, 2022

yes, this PR make the dynamicImport syntax to importGlob and now is easy to make it. 😊https://github.com/vitejs/vite/pull/7756/files#diff-309e5af7d3263d408c73cf68d3c7a2d526438f01ad6e1b56bf08c62d9cafa06dR101-R102

antfu
antfu previously approved these changes May 9, 2022
Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
antfu
antfu previously approved these changes May 9, 2022
@antfu antfu changed the title feat: re-implement dynamic-import-vars feat: rework dynamic-import-vars May 9, 2022
poyoho and others added 4 commits May 10, 2022 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Error: Unknown variable dynamic import: ./icons/user.svg?raw
5 participants