所以我对requirejs和backbone是一个noobie,但是我正在尝试在本地机器上加载blueimp文件上传器的所有依赖项,而不是加载任何外部脚本。这是我的config.js文件:
// Set the require.js configuration for your application.
require.config({
// Initialize the application with the main application file.
deps: ["main"],
paths: {
// JavaScript folders.
libs: "../assets/js/libs",
plugins: "../assets/js/plugins",
vendor: "../assets/vendor",
api : "../assets/js/libs/api",
// Libraries.
jquery: "../assets/js/libs/jquery",
jqueryui: "../assets/js/libs/jquery-ui",
lodash: "../assets/js/libs/lodash",
backbone: "../assets/js/libs/backbone",
handlebars: "../assets/js/libs/handlebars",
bootstrap : "../assets/js/libs/bootstrap",
jqueryuiwidget : '../assets/js/libs/jquery.ui.widget',
jstemplates : '../assets/js/libs/tmpl.min',
jsloadimage : '../assets/js/libs/load-image.min',
jscanvastoblob : '../assets/js/libs/canvas-to-blob.min',
iframetransport : '../assets/js/libs/jquery.iframe-transport',
fileupload : '../assets/js/libs/jquery.fileupload',
fileuploadfp : '../assets/js/libs/jquery.fileupload-fp',
fileuploadui : '../assets/js/libs/jquery.fileupload-ui'
},
shim: {
// Backbone library depends on lodash and jQuery.
backbone: {
deps: ["lodash", "jquery", "jqueryui", "api", 'jqueryuiwidget', 'jstemplates', 'jsloadimage', 'jscanvastoblob', 'iframetransport', 'fileupload', 'fileuploadfp', 'fileuploadui'],
exports: "Backbone"
},
handlebars : {
attach: "Handlebars"
},
api : {
attach : "api"
},
bootstrap: {
deps: ["jquery"]
},
// Backbone.LayoutManager depends on Backbone.
"plugins/backbone.layoutmanager": ["backbone"]
}
});
我知道我不应该将所有其他文件作为主干的依赖项,但我只是想把这个东西加载。
会发生什么,它加载时没有任何错误,但是当我查看页面时,它只加载了canvas-to-blob.min.js,load-image.min.js和tmpl.min.js.
有什么想法可能会这样吗?这很奇怪,因为例如,如果我改变其他一个文件的路径是错误的,那么东西会抛出错误并失败,好像它试图加载它一样。但是当它正确的路径时,它就不会加载......
答案 0 :(得分:2)
shim: {
backbone: {
deps: ["lodash", "jquery"],
exports: "Backbone"
},
bootstrap: { deps: ["jquery"] },
widget: { deps: ["jquery"] },
// backbone plugins
"plugins/backbone.layoutmanager": ["backbone"],
"lib/jquery.fileupload": ["jquery", "widget"],
"lib/jquery.fileupload-fp": ["jquery", "lib/load-image", "lib/canvas-to-blob",
"lib/jquery.fileupload"],
"lib/jquery.fileupload-ui": ["jquery", "lib/tmpl", "lib/load-image",
"lib/jquery.fileupload-fp"]
}
你必须在所有js文件的define []部分中通过路径变量替换路径 我做了同样的事情,它对我有用。
答案 1 :(得分:0)
尝试使用load-image而不是来自此源https://github.com/blueimp/JavaScript-Load-Image的load-image.min文件,它适用于我:)