-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.js
61 lines (55 loc) · 1.54 KB
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//from seajs
function getScriptAbsoluteSrc(node) {
return node.hasAttribute ? // non-IE6/7
node.src :
// see http://msdn.microsoft.com/en-us/library/ms536429(VS.85).aspx
node.getAttribute("src", 4);
}
var BUI = window.BUI = window.BUI || {};
BUI.use = seajs.use;
BUI.config = seajs.config;
var scripts = document.getElementsByTagName('script'),
loaderScript = scripts[scripts.length - 1],
src = getScriptAbsoluteSrc(loaderScript),
loaderPath = src.substring(0, src.lastIndexOf('/')),
// 不能用data-debug 因为在把包的时候会把data-debug替换成data
debug = loaderScript.getAttribute('debug') === 'true' ? true : false;
BUI.loaderScript = loaderScript;
//配置bui的路径
seajs.config({
paths: {
'bui': loaderPath
}
});
BUI.setDebug = function(debug) {
BUI.debug = debug;
//只有bui目录下面的文件使用-min.js
var regexp = new RegExp('^(' + loaderPath + '\\S*).js$');
if (!debug) {
seajs.config({
map: [
[regexp, '$1-min.js']
]
});
}
else {
var map = seajs.data.map;
var mapReg;
if (!map) {
return;
};
for (var i = map.length - 1; i >= 0; i--) {
mapReg = map[i][0];
if (Object.prototype.toString.call(mapReg) === '[object RegExp]' && mapReg.toString() === regexp.toString()) {
map.splice(i, 1);
}
};
}
};
BUI.setDebug(debug);
// 所有的模块都是依赖于jquery, 所以定义一个jquery的模块,并直接返回
if (window.jQuery) {
window.define('jquery', [], function() {
return window.jQuery;
});
}