-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
106 lines (87 loc) · 2.57 KB
/
index.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
var lookup = fis.require('hook-commonjs/lookup.js');
var system = require('./system.js');
// 程序入口
var entry = module.exports = function(fis, opts) {
// amd 处理配置项。
opts.forwardDeclaration = true;
opts.skipBuiltinModules = false;
opts.allowOnymous = true;
lookup.init(fis, opts);
// normalize shim
// 规整 shim 配置。
opts.shim && (function() {
var shim = opts.shim;
var normalized = {};
Object.keys(shim).forEach(function(key) {
var val = shim[key];
if (Array.isArray(val)) {
val = {
deps: val
}
}
var info = lookup(fis.util.query(key));
if (!info.file) {
return;
}
normalized[info.file.subpath] = val;
});
opts.shim = normalized;
})();
var ignoreDependencies = opts.ignoreDependencies || [];
if (typeof ignoreDependencies === 'string') {
ignoreDependencies = ignoreDependencies.split(/\s*,\s*/);
} else if (!Array.isArray(ignoreDependencies)) {
ignoreDependencies = [ignoreDependencies];
}
opts.ignoreDependencies = ignoreDependencies.map(function(item) {
return typeof item === 'string' ? fis.util.glob(item, null, {
matchBase: true,
nocase: true
}) : item;
});
fis.on('lookup:file', lookup);
fis.on('standard:js', function(info) {
system(info, opts);
});
fis.on('components:info', function(componentsInfo) {
var componentsDir = (fis.env().get('component.dir') || 'components/').replace(/\/$/, '');
var path = require('path');
var shims = {};
Object.keys(componentsInfo).forEach(function(key) {
var json = componentsInfo[key];
opts.packages = opts.packages || [];
opts.packages.unshift({
name: json.name,
main: json.main || 'index',
location: path.join(componentsDir, json.name)
});
if (json.shim) {
shims[key] = json.shim;
}
});
lookup.init(fis, opts);
Object.keys(shims).forEach(function(key) {
var shim = shims[key];
Object.keys(shim).forEach(function(key2) {
var val = shim[key2];
if (Array.isArray(val)) {
val = {
deps: val
}
}
var info = lookup(fis.util.query(path.join(componentsDir, key, key2)));
if (!info.file) {
return;
}
opts.shim = opts.shim || {};
opts.shim[info.file.subpath] = val;
});
});
});
};
entry.defaultOptions = {
// 用来查找无后缀资源的
extList: ['.js', '.coffee', '.jsx', '.es6', '.ts', '.tsx'],
// 设置包裹时,内容缩进的空格数。
tab: 2
};