forked from imweb/fis3-packager-smart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
74 lines (54 loc) · 1.72 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
/*global fis*/
/*
* 精简打包逻辑,适配特定的业务场景
*/
var DEF_CONF = {
// 脚本占位符
scriptPlaceHolder: '<!--SCRIPT_PLACEHOLDER-->',
// 样式占位符
stylePlaceHolder: '<!--STYLE_PLACEHOLDER-->',
// 资源占位符
resourcePlaceHolder: '<!--RESOURCEMAP_PLACEHOLDER-->',
output: 'pkg/${id}_min.js',
// 自动打包资源
autoPack: false,
ignore: [], // 不打包的模块
ignoreDict: {},
outputResourceMapToMainJs: false,
lib: [], // 指定公共库
libDict: {},
// css 打包成一个文件,适合单页面应用
cssAllInOne: false,
// css 内嵌到html中
cssInline: false,
// 所有同步js打包成一个文件
jsAllInOne: false
};
var _ = fis.util;
var Page = require('./lib/page');
module.exports = function(ret, pack, settings) {
var files = ret.src,
conf = _.assign({}, DEF_CONF, settings);
conf.idMaps = fis.get('idMaps') || {};
Page.combineCache = {};
(conf.ignore || []).forEach(function(ignore) {
conf.ignoreDict[conf.idMaps[ignore] || ignore] = 1;
});
(conf.lib || []).forEach(function(lib) {
conf.libDict[conf.idMaps[lib] || lib] = 1;
});
var urlmapping = ret.urlmapping = {};
Object.keys(files).forEach(function(subpath) {
var file = files[subpath];
if (file.release) {
urlmapping[file.getUrl()] = file;
}
});
Object.keys(files).forEach(function(subpath) {
var file = files[subpath];
// TODO: 这里可以对源做过滤,xxx.inline.html是不需要处理的
if (file.isHtmlLike && !file.page) {
file.page = new Page(file, ret, conf); // 实例化一个页面
}
});
};