我browserify
在一个Backbone
项目中使用并填充owlCarousel
,因为它不是一个commonJS
类似的模块。shim
转换似乎有效,但在我真正需要的时候无效。
我的app.js
文件看起来像:
var settingsView = require("./settingsView.js");
new settingsView();
和我的settingsView
var app = require("./controllers.js"),
$ = require("jQuery"),
Backbone = require("Backbone"),
owlCarousel = require("owlCarousel");
Backbone.$ = $;
module.exports = Backbone.View.extend({
el: ".settings",
events: {
"click .carousel-img": "setBackground",
"click .palette div": "setTextColor"
},
options: {
singleItem: true,
pagination: false,
navigation: true,
mouseDrag: false
},
initialize: function () {
this.initCarousel();
},
initCarousel: function () {
/* This is causing the problem */
this.owlCarousel = this.$el.find(".carousel").owlCarousel(this.options);
}
})
我在哪里package.json
"browser": {
"jquery": "./node_modules/jquery/dist/jquery.js",
"owlCarousel": "./vendor/owl-carousel/owl-carousel/owl.carousel.js"
},
"browserify": {
"transform": [
"browserify-shim"
]
},
"browserify-shim": {
"jquery": "$",
"owlCarousel": {
"depends": ["jquery:$"]
}
}
它给我的错误:
未捕获的类型错误:this.$el.find(...).owlCarousel 不是函数
在运行时。但是,如果我$("div").owlCarousel
在 dom 准备好后在控制台中运行,它就可以工作。