-
Notifications
You must be signed in to change notification settings - Fork 18
/
index.js
77 lines (64 loc) · 2.32 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
var path = require('path');
var lookup = require('./lookup.js');
var wrapJs = require('./wrap.js');
var parseJs = require('./parser.js');
var umd2commonjs = require('./umd2commonjs.js')
// 程序入口
var entry = module.exports = function(fis, opts) {
lookup.init(fis, opts);
fis.on('lookup:file', lookup);
fis.on('standard:js', function(info) {
parseJs(info, opts);
});
fis.on('compile:postprocessor', function(file) {
wrapJs(file, opts);
});
fis.on('components:info', function(componentsInfo) {
var path = require('path');
var componentsDir = path.relative(opts.baseUrl || '.', (fis.env().get('component.dir') || 'components/').replace(/\/$/, ''));
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.paths) {
opts.paths = opts.paths || {};
Object.keys(json.paths).forEach(function(key) {
opts.paths[path.join(json.name, key)] = path.join(componentsDir, json.name, json.paths[key]);
});
}
});
lookup.init(fis, opts);
});
fis.on('node_modules:info', function (packages) {
opts.packages = packages.packages
lookup.init(fis, opts)
});
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;
});
};
entry.defaultOptions = {
// 是否前置依赖,如果是 mod.js 千万别配置成 true
// 给那种自己实现 loader 的用户使用的。
forwardDeclaration: false,
// 当前置依赖启动的时候才有效,用来控制是否把内建的 `require`, `exports`, `module` 从第二个参数中去掉。
skipBuiltinModules: true,
// 用来查找无后缀资源的
extList: ['.js', '.coffee', '.jsx', '.es6'],
// 设置包裹时,内容缩进的空格数。
tab: 2,
sourceMap: true,
};