Gui*_*rmo 5 javascript node.js typeahead.js gulp gulp-babel
在node.js项目中使用babel时,我正在尝试将所有文件捆绑到一个已编译和缩小的js文件中.
我正在使用gulp-babel 6.1.2运行babel,我已经安装了ES-2015预设(6.13.2).
我正在使用我的文件构建一个包,并且输入0.11.1,问题是当运行gulp任务并通过babel管道时,输入的功能不起作用(Uncaught TypeError:无法设置未定义的属性'Bloodhound').如果我再次运行任务,从管道中删除babel命令,一切正常.
我知道我可以构建两个单独的包,一个用于我的文件,另一个用于外部文件,但我想知道为什么它失败了.
我的任务:
gulp.task('bundleCheckoutDesktopJs', function () {
var js = ['./src/js/project/external/*', './src/js/project/common/*', './src/js/project/*'];
return gulp.src(js)
.pipe(babel())
.pipe(concat('project.min.js'))
.pipe(uglify())
.pipe(gulp.dest('statics/js/'));
});
Run Code Online (Sandbox Code Playgroud)
调查一段时间后我获得的结果(typeahead.js):
(function(root, factory) {
if (typeof define === "function" && define.amd) {
define("bloodhound", [ "jquery" ], function(a0) {
return root["Bloodhound"] = factory(a0);
});
} else if (typeof exports === "object") {
module.exports = factory(require("jquery"));
} else {
// Root seems to be undefined here....
root["Bloodhound"] = factory(jQuery);
}
})
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激,提前感谢.
小智 0
插件代码:在立即调用函数中,将第一个参数指定为window。如果使用箭头函数,可能找不到this上下文。
/*!
* typeahead.js 0.11.1
* https://github.com/twitter/typeahead.js
* Copyright 2013-2015 Twitter, Inc. and other contributors; Licensed MIT
*/
(function(root, factory) {
if (typeof define === "function" && define.amd) {
define("bloodhound", [ "jquery" ], function(a0) {
return root["Bloodhound"] = factory(a0);
});
} else if (typeof exports === "object") {
module.exports = factory(require("jquery"));
} else {
root["Bloodhound"] = factory(jQuery);
}
})(this, function($) { // here replace 'this' with window
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
198 次 |
| 最近记录: |