我正在移植一个应用程序,它使用System.import从traceur到Babel。我的简化HTML如下所示:
<script src="../node_modules/babel-core/browser.js"></script>
<script src="../node_modules/es6-module-loader/dist/es6-module-loader-dev.js"></script>
<script>
System.transpiler = 'babel';
System.import('./css');
</script>这给了我
Uncaught (in promise) File not found: http://connect:8000/sam/css
Error loading http://connect:8000/sam/css如果我指定了./css.js,并使用了.js扩展,那么它就能工作。但是,然后在css.js内部以及整个系统中导入表单
import 'foo';失败。
似乎ES6-模块加载程序需要.js扩展。我注意到涉及演示页面的ES6-模块加载器中的一些提交,它将.js扩展添加到导入的名称中。在此页上,我也看到
默认情况下,.js扩展也不再添加。这些更改是过渡到新规范工作的一部分。有关更多信息,请参见whatwg/loader#52上的讨论。如果需要,可以使用自定义钩子轻松地添加.js扩展。
但我不知道你指的是哪种钩子,也不知道怎么写。
我知道在浏览器中动态加载和转换可能并不理想,也不是一种健壮的生产方法。但是,这个特定的应用程序动态地加载单个的ES6文件,我需要暂时坚持这样做。
我的问题是:ES6模块加载程序是否需要.js扩展名,还是有任何方法告诉它默认情况下查找.js文件?
发布于 2015-08-02 18:42:46
最后,基于locate的文档,我重写了https://github.com/ModuleLoader/es6-module-loader/blob/master/docs/loader-extensions.md钩子。
var systemLocate = System.locate;
System.locate = function(load) {
var System = this; // its good to ensure exact instance-binding
return Promise.resolve(systemLocate.call(this, load)).then(function(address) {
return address + '.js';
});
} https://stackoverflow.com/questions/31764111
复制相似问题