-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (41 loc) · 1.28 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
/**
* @file: index.js
* @author: l5oo00
*/
'use strict';
let babel = require('babel-core');
let nodePathLib = require('path');
// 在这里生成 babel helper, 并写入依赖
module.exports = function (ret, conf, settings, opt) {
let helperNameList = [];
fis.util.map(ret.src, (src, file) => {
let list = file.helperNameList || [];
list.forEach(name => {
if (helperNameList.indexOf(name) === -1) {
helperNameList.push(name);
}
});
});
if (helperNameList.length === 0) {
return;
}
// babel helper 收集完成, 在这里生成 统一的文件
let helperFilePath = opt.helperFilePath || 'widget/babel_helpers.js';
let helperCode = babel.buildExternalHelpers(helperNameList, 'umd');
let filePath = nodePathLib.join(fis.project.getProjectPath(), helperFilePath);
let file = fis.file.wrap(filePath);
file.setContent(helperCode);
file.useBabel = false;
file.isMod = true;
let subPath = file.subpath;
ret.src[subPath] = file;
let id = file.getId();
ret.ids[id] = file;
file.map = {
uri: file.getUrl(),
type: file.rExt.replace(/^\./, '')
};
ret.map.res[id] = file.map;
ret.pkg[subPath] = file;
fis.compile.process(file);
};