ES6:从 URL 导入模块 [英] ES6: import module from URL
问题描述
是否可以在 ES6 中从外部 url 导入 javascript 模块?
Is it possible to import javascript module from external url in ES6?
我尝试过(使用 babel-node):
I tried (using babel-node):
import mymodule from 'http://...mysite.../myscript.js';
// Error: Cannot find module 'http://...mysite.../myscript.js'
推荐答案
2018 更新:模块加载器规范现在是 ES 规范的一部分 - 您所描述的内容在 <script type= 中是允许和可能的浏览器中的module">
以及带有 Node.js 和 Deno 的自定义 --loader
(如果你喜欢的话).
2018 Update: The module loader spec is now a part of the ES Spec - what you are describing is allowed and possible with <script type="module">
in browsers and with a custom --loader
with Node.js as well as with Deno if you're into that.
模块加载器规范和导入/导出语法是分开的.所以这是模块加载器的一个属性(不是 ES 规范的一部分).如果您使用支持 SystemJS 等插件的模块加载器.
The module loader spec and the import/export syntax are separate. So this is a property of the module loader (not a part of the ES spec). If you use a module loader that supports plugins like SystemJS.
这篇关于ES6:从 URL 导入模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!