forked from seajs/seajs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.js
90 lines (70 loc) · 1.92 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**
* config.js - The configuration for the loader
*/
var configData = config.data = {
// The root path to use for id2uri parsing
base: (function() {
var ret = dirname(loaderUri)
// If loaderUri is `http://test.com/libs/seajs/1.0.0/sea.js`, the baseUri
// should be `http://test.com/libs/`
var m = ret.match(/^(.+\/)seajs\/\d[^/]+\/$/)
if (m) {
ret = m[1]
}
return ret
})(),
// The charset for requesting files
charset: "utf-8"
// debug: false - Debug mode
// alias - The shorthand alias for module id
// vars - The {xxx} variables in module id
// map - An array containing rules to map module uri
// preload - Modules that are needed to load before all other modules
}
function config(data) {
for (var key in data) {
if (hasOwn(data, key)) {
var prev = configData[key]
var curr = data[key]
// For alias, vars
if (prev && /alias|vars/.test(key)) {
for (var k in curr) {
if (hasOwn(curr, k)) {
var val = curr[k]
if (k in prev) {
checkConfigConflict(prev[k], val, k, key)
}
prev[k] = val
}
}
}
else {
// For map, preload
if (isArray(prev)) {
curr = prev.concat(curr)
}
// Set config
configData[key] = curr
// Make sure that `configData.base` is an absolute path
if (key === 'base') {
makeBaseAbsolute()
}
}
}
}
return seajs
}
seajs.config = config
function checkConfigConflict(prev, curr, k, key) {
if (prev !== curr) {
log("The config of " + key + '["' + k + '"] is changed from "' +
prev + '" to "' + curr + '"', "warn")
}
}
function makeBaseAbsolute() {
var base = configData.base
if (!isAbsolute(base)) {
configData.base = id2Uri((isRoot(base) ? "" : "./") + base
+ (base.charAt(base.length - 1) === "/" ? "" : "/"))
}
}