Replies: 2 comments 3 replies
-
|
some related discussion in webpack webpack/webpack#6437 (comment), it's the recommend way to deal virtual module in webpack, @sodatea and @antfu may have better ideas |
Beta Was this translation helpful? Give feedback.
3 replies
-
|
The RFC now is blocked by the unimplemented new architecture of RSpack. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
data:text/javascriptprotocolSummary
Supports bundling code like'
Motivation
It seems in the spec, but I forgot which one.
It's one way to deal with virtual files.
Guide-level explanation
Let's say you have an idea that you want to inject some runtime code in bundling.
The idea requests you to deal with virtual modules.
virtual modules are javascript files that do not exist on the hard disks.
See the way how vite does it.
You could see that vite intercepts the procedure of reading files from disk.
And that's the way using
data:text/javascriptprotocol.RSpack is ok to use Vite's way, but it has some problems. Such as the
virtualModuleIdwill be exposed to other plugins. Since Vite's way is only a conversion not in the spec, people don't have a consistent solution, which could lead to some problems.Reference-level explanation
How to handle importing modules by relative paths in the
data:protocol.For example, attempting to load
./foofromdata:text/javascript,import "./foo";I tend to raise an error just like node.js did.
Drawbacks
It's in the spec, no significant reasons we shouldn't do it.
Rationale and alternatives
Why is this design the best in the space of possible designs?
It's in the spec.
What other designs have been considered and what is the rationale for not choosing them?
See the Motivation part.
Prior art
Webpack
resolveForSchemewhen resolving a module inNormalModuleFactoryimport { msg } from 'data:text/javascript,export const msg = "from virtual module"'will be parsed to twoDependencys.HarmonyImportSideEffectDependencyHarmonyImportSpecifierDependencyNormalModuleusing the twoDpendencys(as a whole) inNormalModuleFactory#createModuleRequesthas scheme, Webpack will callresolveForSchemehook and the DataURI plugin will use the hook to return the information ofdata:...to Webpack.NormalModule.NormalModulerendering,NormalModulewill callreadResourcehook to get original source code.readResourceForSchemehook to provide source code.readResourceForSchemehook is wrapper ofreadResourcehook, which will be deprecated in Webpack 6.Related
Unresolved questions
Nope
Future possibilities
We should also supports
data:text,htmlanddata:text,css.Beta Was this translation helpful? Give feedback.
All reactions