我遇到了一个dojo库错误,我试图在即将发布之前解决它。该问题已本地化为单个文件(dojo/on
),我可以通过更改dojo/on
来修复该错误。
我尝试解决此问题的方法是使用map
中的dojoConfig
属性。
Dojo配置:
dojoConfig = {
... other stuff ...
map: {
"*": {
"dojo/on": "myPackage/patches/on"
}
}
}
除了在dojo/on
中解决问题之外,我还用绝对路径替换了require中的相对路径。新on
看起来像这样:
define(["dojo/has!dom-addeventlistener?:dojo/aspect", "dojo/_base/kernel", "dojo/sniff"], function(aspect, dojo, has){
"use strict";
alert("HI From new on - I only work with unbuilt dojo"); // Rest of on is the same.
当我针对dojo源运行时,这很有用。
当我对抗CDN时,这会停止工作。据我所知,myPackage/patches/on
永远不会被加载(firebug net panel& fiddler)。发生的另一件奇怪的事情是这些请求发送到我的服务器:
http://.../patches/dojo-1.9.4/has.js
http://.../patches/dojo-1.9.4/sniff.js
http://.../patches/dojo-1.9.4/_base/kernel.js
结果是页面没有加载,控制台没有显示其他错误。
修改 - 完整示例页面:
<!DOCTYPE html>
<html >
<head>
<script>
dojoConfig = {
parseOnLoad: true,
packages: [
{name: "my", location: "//localhost/dojoSandbox" }
],
map: {
"*": {
"dojo/on" : "my/patches/on-dojo-1.9.4"
}
}
}
</script>
<!-- Using a CDN doesn't work. Crap -->
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.9.1/dojo/dojo.js"></script>
<link href="//ajax.googleapis.com/ajax/libs/dojo/1.9.1/dijit/themes/claro/claro.css" rel="stylesheet" type="text/css">
<!-- Using dojo source works great!
<script src="//localhost/dojo/dojo.js"></script>
<link href="//localhost/dijit/themes/claro/claro.css" rel="stylesheet" type="text/css">
-->
</head>
<body class="claro">
<div id="hSliderDiv"></div>
<script>
require(["dijit/form/HorizontalSlider", "dojo/domReady!"], function(HorizontalSlider){
new HorizontalSlider({
onChange: function(value){
console.log(value);
}
}, "hSliderDiv").startup();
});
</script>
</body>
</html>
控制台: