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

[Feature]: virtual module support #7478

Open
hardfist opened this issue Aug 7, 2024 · 8 comments
Open

[Feature]: virtual module support #7478

hardfist opened this issue Aug 7, 2024 · 8 comments
Assignees
Labels
feat New feature or request team The issue/pr is created by the member of Rspack.
Milestone

Comments

@hardfist
Copy link
Contributor

hardfist commented Aug 7, 2024

What problem does this feature solve?

Definition

Virtual Module: module not exists on real filesystem

Background

Virtual module is widely used in bundler ecosystem( vite、webpack), and different bundlers take different approaches,
webpack uses https://www.npmjs.com/package/webpack-virtual-modules?activeTab=readme to support virtual module and vite use https://vitejs.dev/guide/api-plugin.html#virtual-modules-convention to support virtual module
Currently rspack implement a naive implementation of webpack-virtual-modules(https://github.com/rspack-contrib/rspack-plugins/tree/main/packages/plugin-virtual-module) which has some limitation.

Since Rspack already supports unplugin so it can actually support both implementation, but too many flexibilities may but ecosystem in chaos(just like vite's virtual module path can be virtual:my-module and \0xxx which makes it harder to unify plugin usage).

resolve hook vs input_filesystem

webpack use patched input_filesystem to implement virtual modules which limits virtual module path to be real path url(which may be not bad), so the internal resolver can handle it correctly, vite & rollup use resolve and load and virtual-module-convention to handle virtual path(which is more flexible).

It seems webpack-virtual-modules using patched input_filesystem strategy is not a strong limitation in real world usage and is much simpler and performance friendly.

There're 3 ways Rspack can implement virtual module like webpack did

  • Implement builtin rust version of virtualModulePlugin: performance friendly
  • Compatible with webpack-virtual-modules, which needs Rspack implement input_filesystem options, which may cause performance regression since every fs call needs trigger napi communication
  • Maintain the status quo

It seems the second way is more flexible and ecosystem friendly, we may need to investigate the performance regression, if the regression is acceptable we can be compatible with webpack-virtual-modules, then do we still need implement a virtualModulePlugin for better out of box experience.

What does the proposed API of configuration look like?

if we choose implement rust version of this plugin then same as https://www.npmjs.com/package/webpack-virtual-modules

@hardfist hardfist added feat New feature or request pending triage The issue/PR is currently untouched. labels Aug 7, 2024
@github-actions github-actions bot added the team The issue/pr is created by the member of Rspack. label Aug 7, 2024
@hardfist hardfist assigned hardfist and unassigned SyMind Aug 28, 2024
@jerrykingxyz jerrykingxyz removed the pending triage The issue/PR is currently untouched. label Sep 2, 2024
@hardfist hardfist added this to the 1.1.0 milestone Sep 5, 2024
@ahabhgk
Copy link
Contributor

ahabhgk commented Sep 10, 2024

This probably can split into two layer: memory input filesystem and virtual modules plugin, memory input filesystem for more general use cases and virtual modules plugin is just a wrapper plugin based on memory input filesystem

@hardfist
Copy link
Contributor Author

hardfist commented Sep 11, 2024

This probably can split into two layer: memory input filesystem and virtual modules plugin, memory input filesystem for more general use cases and virtual modules plugin is just a wrapper plugin based on memory input filesystem

yeah, that's the plan, but when you say "memory input filesystem" you mean

  • passing memory input filesystem from js side to rust side and every read trigger js side readfile call
  • passing memory input(like object) to rust side and every read will only trigger rust side readfile call

@ahabhgk
Copy link
Contributor

ahabhgk commented Sep 11, 2024

Definitely the second one, but we need to consider to make a better API for user. A MemoryFileSystemRspackPlugin or an enum/options of compiler.inputFileSystem that passes to rust

@hardfist
Copy link
Contributor Author

Definitely the second one, but we need to consider to make a better API for user. A MemoryFileSystemRspackPlugin or an enum/options of compiler.inputFileSystem that passes to rust

yes, I will make a RFC about InputFilesystem and VirtualModule support

Copy link

stale bot commented Nov 10, 2024

This issue has been automatically marked as stale because it has not had recent activity. If this issue is still affecting you, please leave any comment (for example, "bump"). We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

@stale stale bot added the stale label Nov 10, 2024
@hardfist
Copy link
Contributor Author

bump

@stale stale bot removed the stale label Nov 10, 2024
@watsonhaw5566
Copy link

这个 feature 还有在进行吗, hardfist 兄

@hardfist
Copy link
Contributor Author

这个 feature 还有在进行吗, hardfist 兄

no, maybe we will use inputFs to implement when we solve the performance problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat New feature or request team The issue/pr is created by the member of Rspack.
Projects
None yet
Development

No branches or pull requests

5 participants