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

docs: virtual modules internal convention #5553

Merged
merged 3 commits into from Nov 17, 2021

Conversation

patak-dev
Copy link
Member

Description

See added docs and test

AFAICS, if plugins in the ecosystem would follow this rollup convention, then we wouldn't have dealt with issues as in #2904 and #5421


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Shinigami92
Shinigami92 previously approved these changes Nov 4, 2021
@patak-dev patak-dev requested a review from antfu November 5, 2021 13:36
bluwy
bluwy previously approved these changes Nov 5, 2021
@patak-dev
Copy link
Member Author

@bluwy are you using virtual modules in vite-plugin-svelte? I'm going to do a PR at one point for vite core to start using \0 for internal virtual modules to see how it works. AFAICS, the only issue is that we'll get slightly worse URLs for them but since \0 is used in Rollup core (for example during sourcemaps processing), I think it is a good idea to use it.

@bluwy
Copy link
Member

bluwy commented Nov 5, 2021

Yeah vite-plugin-svelte also uses virtual modules for Svelte files, similar to how the Vue plugin processes them. In short, for every Svelte file that has CSS, a /path/to/component.svelte&type=style&lang.css counterpart is created. We have a function for it.

For this case we would need to prepend that path with \0, which is a bit weird and makes things feel separated, but it might be good for consistency anyways.

@patak-dev
Copy link
Member Author

Interesting, I was thinking of the helper virtual modules (like the module preload polyfill). In the case of the modules generated from the SFCs, the file is still there, so maybe this doesn't apply (you want the sourcemap to point to the original .svelte file, no?)

@bluwy
Copy link
Member

bluwy commented Nov 5, 2021

Hmm yeah putting it that way, perhaps SFCs don't need to follow the convention after all, as long as the virtual module directly derives from the single real module. Maybe it would benefit to have this in the docs too 🤔

@patak-dev patak-dev dismissed stale reviews from bluwy and Shinigami92 via dd75793 November 13, 2021 12:36
@patak-dev
Copy link
Member Author

patak-dev commented Nov 13, 2021

@bluwy @aleclarson would you review if the added note is clear enough?

Note that modules directly derived from a real file, as in the case of a script module in a Single File Component (like a .vue or .svelte SFC) don't need to follow this convention. SFCs generally generate a set of submodules when processed but the code in these can be mapped back to the filesystem. Using \0 for these submodules would prevent sourcemaps from working correctly.

Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

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

Minor typo, but otherwise looks good to me 👍

docs/guide/api-plugin.md Outdated Show resolved Hide resolved
Co-authored-by: Bjorn Lu <34116392+bluwy@users.noreply.github.com>
@patak-dev patak-dev merged commit 04016df into main Nov 17, 2021
@antfu antfu deleted the docs/virtual-modules-internal-convention branch December 24, 2021 05:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants