-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
49 lines (39 loc) · 1.19 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
var fs = require('fs');
var path = require('path');
var rootPath = path.resolve(__dirname, '..');
function getFileList(dir, filelist) {
var files = fs.readdirSync(dir);
filelist = filelist || [];
files.forEach(function(file) {
var filePath = path.join(dir, file);
if (fs.statSync(filePath).isDirectory()) {
var childList = getFileList(filePath, []);
filelist.push({
[file]: childList
});
} else {
filelist.push(file);
}
});
return filelist;
};
function FlielistPlugin(options) {
this.filePath = path.join(rootPath, options.filePath);
this.exportPath = options.exportPath;
}
FlielistPlugin.prototype.apply = function(compiler) {
compiler.plugin('emit', (compilation, callback) => {
var fileList = getFileList(this.filePath, []);
fileList = JSON.stringify(fileList, null, 4);
compilation.assets[this.exportPath] = {
source: function() {
return fileList;
},
size: function() {
return fileList.length;
}
};
callback();
});
};
module.exports = FlielistPlugin;