我正在使用ES6 modules转储到ES5与traceur。
Transpilation通过咕噜做+ grunt-traceurJavaScript ES6模块+ traceur
Traceur允许您选择要使用的模块处理程序:它自己的,AMD,CommonJS的或内联。
我已经尝试了大部分,但似乎没有工作。为什么?
TestClass.js
export default class TestClass {
constructor() {
alert('test');
}
}
Main.js
import TestClass from './TestClass';
var test = new TestClass();
Gruntfile.js(提取物)
traceur: {
options: {
experimental: true,
blockBinding: true,
modules: 'amd'
}
}
的index.html(摘录)
<script src="js/vendor/traceur-runtime.js"></script>
<script src="js/vendor/require.js"></script>
<script defer async src="js/compiled/Main.js"></script>
错误给出
Uncaught Error: Mismatched anonymous define() module: function ($__0) {
似乎there are issues与繁重的插件,但即使使用的是旧版本,似乎并没有帮助。
代码改编自an article。
您可能还想看看[6to5](http://6to5.github.io/)。它有很多不同格式的[模块格式器](http://6to5.github.io/modules.html),可以很好地与其他工具配合使用。 – 2014-12-05 03:03:20