导航菜单
首页 >  Data URLs  > data: 导入

data: 导入

新增于: v12.10.0

data: URL 支持使用以下 MIME 类型导入:

text/javascript 用于 ES 模块application/json 用于 JSONapplication/wasm 用于 Wasmimport 'data:text/javascript,console.log("hello!");';import _ from 'data:application/json,"world!"' assert { type: 'json' };

data: URL 仅解析内置模块的裸说明符和绝对说明符。解析相对说明符不起作用,因为 data: 不是特殊协议。例如,尝试从 data:text/javascript,import "./foo"; 加载 ./foo 无法解析,因为 data: URL 没有相对解析的概念。

Added in: v12.10.0

data: URLs are supported for importing with the following MIME types:

text/javascript for ES modulesapplication/json for JSONapplication/wasm for Wasmimport 'data:text/javascript,console.log("hello!");';import _ from 'data:application/json,"world!"' assert { type: 'json' };

data: URLs only resolve bare specifiers for builtin modulesand absolute specifiers. Resolvingrelative specifiers does not work because data: is not aspecial scheme. For example, attempting to load ./foofrom data:text/javascript,import "./foo"; fails to resolve because thereis no concept of relative resolution for data: URLs.

相关推荐: