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: import.meta.glob with as: 'path' #14269

Closed
wants to merge 3 commits into from
Closed

Conversation

antfu
Copy link
Member

@antfu antfu commented Sep 3, 2023

Description

import.meta.glob is great for accessing folders directly from the client code. However, the current state it always implies some side effects (importing modules, or bundling assets).

In some cases, we just want to have the info of the file exists the info, and do something with them later.

For example, I might want to get a list of assets I have under the /public folder. Current we can use as: url to do:

const files = Object.values(import.meta.glob('../public/**.txt', { as: 'url', eager: true }))

// I might fetch it manually later, or do something else
const content = await fetch(files[0])

However, url will inject the imports and bundle them as assets (double assets, as they are already copied as public assets). Meanwhile, this warning will be printed at dev time:

Instead of /public/foo.txt?url, use /foo.txt?url.
Assets in the public directory are served at the root path.

So, this PR added a as type path to import.meta.glob for only globbing the import path without any side-effects.

Additional context


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 PR Title 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.

@stackblitz
Copy link

stackblitz bot commented Sep 3, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@sapphi-red sapphi-red added the p2-nice-to-have Not breaking anything but nice to have (priority) label Sep 6, 2023
@patak-dev patak-dev mentioned this pull request Sep 8, 2023
4 tasks
@antfu
Copy link
Member Author

antfu commented Dec 16, 2023

Closing this as we might consider remove as option and this can be workarounded with a userland plugin

@antfu antfu closed this Dec 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2-nice-to-have Not breaking anything but nice to have (priority)
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants