我正在使用 [gulp-traceur][1] 在我的 angularjs 应用程序 (1.x) 中将 es6 编译为 js。当我尝试编译 for
循环时,出现错误:
ReferenceError: $traceurRuntime is not defined
看起来我需要将 $traceurRuntime 注入(inject)我的 Controller 或其他东西。谁能帮帮我?
最佳答案
$traceurRuntime
是全局范围内的对象,而不是 Angular 可注入(inject)对象。该对象来自您的应用程序中包含的 traceur 运行时脚本文件 (traceur-runtime.js
)。 Make sure you include the traceur.RUNTIME_PATH
所以 gulp 任务知道在编译期间在哪里找到它并包含它。
假设您的 gulpfile 看起来像这样:
// gulpfile.js
var traceur = require('gulp-traceur');
// ...
gulp.task('build', function() {
return gulp.src([
traceur.RUNTIME_PATH, // <-- add this
'src/**/*.*'
])
.pipe(traceur({ /* traceur config */ })
.pipe(gulp.dest('/dist'));
});
关于javascript - 引用错误 : $traceurRuntime is not defined (in angularjs app),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27538418/