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
-
data:text/javascript
protocolSummary
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/javascript
protocol.RSpack is ok to use Vite's way, but it has some problems. Such as the
virtualModuleId
will 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
./foo
fromdata: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
resolveForScheme
when resolving a module inNormalModuleFactory
import { msg } from 'data:text/javascript,export const msg = "from virtual module"'
will be parsed to twoDependency
s.HarmonyImportSideEffectDependency
HarmonyImportSpecifierDependency
NormalModule
using the twoDpendency
s(as a whole) inNormalModuleFactory#create
ModuleRequest
has scheme, Webpack will callresolveForScheme
hook and the DataURI plugin will use the hook to return the information ofdata:...
to Webpack.NormalModule
.NormalModule
rendering,NormalModule
will callreadResource
hook to get original source code.readResourceForScheme
hook to provide source code.readResourceForScheme
hook is wrapper ofreadResource
hook, which will be deprecated in Webpack 6.Related
Unresolved questions
Nope
Future possibilities
We should also supports
data:text,html
anddata:text,css
.Beta Was this translation helpful? Give feedback.
All reactions