-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
48 lines (38 loc) · 1.39 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
'use strict';
var CreateHashFilePlugin = (function () {
const write = require('write');
const path = require('path');
function CreateHashFilePlugin(options){
if (options === void 0) {
throw new Error(`Please provide 'options' for the CreateHashFilePlugin config`);
}
this.options = options;
}
function _createFile(compStats, filePath, fileName, content) {
const fullPath = path.join(filePath, fileName);
write.sync(fullPath, content.replace(/\[hash\]/g, compStats.hash));
}
CreateHashFilePlugin.prototype.apply = function (compiler) {
const createFile = (compStats) => {
this.options.forEach(option => {
if (option.path == null) {
throw new Error(`Please provide 'options.path' in the CreateHashFilePlugin config`);
}
if (option.fileName == null) {
throw new Error(`Please provide 'options.fileName' in the CreateHashFilePlugin config`);
}
if (option.content == null) {
throw new Error(`Please provide 'options.content' in the CreateHashFilePlugin config`);
}
_createFile(compStats, option.path, option.fileName, option.content);
});
};
if (!!compiler.hooks) {
compiler.hooks.done.tap('CreateFileWebpack', createFile);
} else {
compiler.plugin('done', createFile);
}
};
return CreateHashFilePlugin;
})();
module.exports = CreateHashFilePlugin;