forked from javascript-tutorial/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwriteVersionsPlugin.js
More file actions
executable file
·33 lines (25 loc) · 973 Bytes
/
Copy pathwriteVersionsPlugin.js
File metadata and controls
executable file
·33 lines (25 loc) · 973 Bytes
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
let fs = require('fs-extra');
let path = require('path');
function WriteVersionsPlugin(file) {
this.file = file;
}
WriteVersionsPlugin.prototype.writeStats = function(compiler, stats) {
stats = stats.toJson();
let assetsByChunkName = stats.assetsByChunkName;
for (let name in assetsByChunkName) {
if (assetsByChunkName[name] instanceof Array) {
assetsByChunkName[name] = assetsByChunkName[name].map(function(path) {
return compiler.options.output.publicPath + path;
});
} else {
assetsByChunkName[name] = compiler.options.output.publicPath + assetsByChunkName[name];
}
}
// console.log("WRITING VERSIONS", this.file, assetsByChunkName);
fs.ensureDirSync(path.dirname(this.file));
fs.writeFileSync(this.file, JSON.stringify(assetsByChunkName));
};
WriteVersionsPlugin.prototype.apply = function(compiler) {
compiler.plugin("done", this.writeStats.bind(this, compiler));
};
module.exports = WriteVersionsPlugin;