简体   繁体   English

将动态ES6 System.import转换为ES5(AMD或其他)

[英]Transpiling dynamic ES6 System.import to ES5 (amd or other)

I'm stuck with dynamic requering es6 modules by invoking them through: 我陷入了动态重新查询es6模块的问题,方法是通过以下方式调用它们:

System.import('SOME_PATH').then(function (MODULE_FROM_SOME_PATH) {});

It works well with es6-module-loader and babel runtime compilation in browser, but when i want to precompile it to ES5 syntax (for production uses) it just passes System.import expression in code, leaving in practically untouched, just replacing System.import with equivalent System['import'] . 它可以与es6-module-loader和babel运行时编译器在浏览器中很好地es6-module-loader ,但是当我想将其预编译为ES5语法(用于生产用途)时,它只是在代码中传递System.import表达式,几乎没有改动,仅替换System.import具有等效System['import']

I've tried gulp-babel and babel npm package. 我已经尝试过gulp-babel和babel npm软件包。 So when opened in browser it gives expected module loading error. 因此,在浏览器中打开时,会产生预期的模块加载错误。 How can i transpile my code to AMD syntax for ES5 . 如何将我的代码转换为ES5 AMD语法。 Hoping for your help. 希望能为您提供帮助。

Just pushed babel-plugin-system-import-transformer that replaces System.import to the equivalent UMD import (AMD, CommonnJS & Global module imports). 只需将替换System.import的babel-plugin-system-import-transformer推送到等效的UMD导入(AMD,CommonJS和Global模块导入)。

I have also created a separate localforage branch that uses System.import statements as an example. 我还创建了一个单独的localforage分支 ,该分支使用System.import语句作为示例。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM