Javascript RequireJS未加载Mustache窗口对象
我正在实现为我的Jekyll站点描述的搜索功能,但它需要六个单独的JavaScript文件才能工作,所以我想使用RequireJS将所有这些文件作为依赖项加载。事情不正常,错误控制台消息会产生不同的结果Javascript RequireJS未加载Mustache窗口对象,javascript,requirejs,mustache,Javascript,Requirejs,Mustache,我正在实现为我的Jekyll站点描述的搜索功能,但它需要六个单独的JavaScript文件才能工作,所以我想使用RequireJS将所有这些文件作为依赖项加载。事情不正常,错误控制台消息会产生不同的结果 Webkit说未捕获引用错误:未定义胡须。发送消息的文件jquery.lunr.search.js,它是作为依赖项列出的最后一个js文件 Firefox和Opera分别返回两个不同文件的控制台错误版本:SecondLevelDomains.js和IPv6.js 正在寻找IE浏览器 RE:让小
- Webkit说
。发送消息的文件未捕获引用错误:未定义胡须
,它是作为依赖项列出的最后一个js文件jquery.lunr.search.js
- Firefox和Opera分别返回两个不同文件的控制台错误版本:
和SecondLevelDomains.js
IPv6.js
- 正在寻找IE浏览器
场地结构
index.html
js
|__require.js
|__config.js
|__search.js
|__vendor
|__date.format.js
|__jquery.js
|__jquery.lunr.search.js
|__lunr.min.js
|__mustache.js
|__URI.min.js
config.js
如下所示:
requirejs.config({
baseUrl: "/js",
deps: ["search"],
paths: {
jquery: "vendor/jquery",
lunr: "vendor/lunr.min",
mustache: "vendor/mustache",
dateFormat: "vendor/date.format",
uri: "vendor/URI.min",
LunrSearch: "vendor/jquery.lunr.search"
},
shim: {
jquery: {
exports: 'jquery'
},
lunr: {
exports: 'lunr'
},
'mustache': {
exports: 'Mustache'
},
dateFormat: {
exports: 'dateFormat'
},
uri: {
deps: ['jquery'],
exports: 'uri'
},
LunrSearch: {
deps: ['jquery', 'mustache'],
exports: 'LunrSearch'
}
}
});
define("search", ["jquery", "lunr", "mustache", "uri", "dateFormat", "LunrSearch"],
function($, lunr, mustache, dateFormat, uri, LunrSearch) {
$('#search-query').lunrSearch({
indexUrl: '/search.json', // URL of the `search.json` index data for your site
results: '#search-results', // jQuery selector for the search results container
entries: '.entries', // jQuery selector for the element to contain the results list, must be a child of the results element above.
template: '#search-results-template' // jQuery selector for the Mustache.js template
});
});
而search.js
(应该会启动所有程序)如下所示:
requirejs.config({
baseUrl: "/js",
deps: ["search"],
paths: {
jquery: "vendor/jquery",
lunr: "vendor/lunr.min",
mustache: "vendor/mustache",
dateFormat: "vendor/date.format",
uri: "vendor/URI.min",
LunrSearch: "vendor/jquery.lunr.search"
},
shim: {
jquery: {
exports: 'jquery'
},
lunr: {
exports: 'lunr'
},
'mustache': {
exports: 'Mustache'
},
dateFormat: {
exports: 'dateFormat'
},
uri: {
deps: ['jquery'],
exports: 'uri'
},
LunrSearch: {
deps: ['jquery', 'mustache'],
exports: 'LunrSearch'
}
}
});
define("search", ["jquery", "lunr", "mustache", "uri", "dateFormat", "LunrSearch"],
function($, lunr, mustache, dateFormat, uri, LunrSearch) {
$('#search-query').lunrSearch({
indexUrl: '/search.json', // URL of the `search.json` index data for your site
results: '#search-results', // jQuery selector for the search results container
entries: '.entries', // jQuery selector for the element to contain the results list, must be a child of the results element above.
template: '#search-results-template' // jQuery selector for the Mustache.js template
});
});
有什么想法吗?谢谢 你确定胡子需要垫片吗?主持人:谢谢您的回复!是的,我看到了答案,我移除了垫片并对其进行了测试。不幸的是,它不起作用。有没有可能查看测试页面或JSFIDLE?发帖人:感谢您的帮助!链接是。如果检查控制台消息,您将看到没有定义Mustache对象。