-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (31 loc) · 1.05 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
const fs = require('fs');
const path = require('path');
class HarmonyRenderFunctionGenerator {
constructor(options) {
this.options = options;
}
apply(compiler) {
compiler.hooks.emit.tapAsync('HarmonyRenderFunctionGeneratorPlugin', (compilation, callback) => {
const wrapFunction = this.options.wrapFunction || 'renderFunc';
// 获取所有输出的文件名
const outputNames = Object.keys(compilation.assets);
outputNames.forEach(outputName => {
const asset = compilation.assets[outputName];
let wrappedContent = `export function ${wrapFunction}(__Hummer__, __GLOBAL__) {\n`;
wrappedContent += asset.source();
wrappedContent += '\n}\n';
// 重新设置输出文件的内容
compilation.assets[outputName] = {
source: function() {
return wrappedContent;
},
size: function() {
return wrappedContent.length;
}
};
});
callback();
});
}
}
module.exports = HarmonyRenderFunctionGenerator;