-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathindex.js
47 lines (37 loc) · 1.34 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
'use strict';
var CreateFilePlugin = (function () {
const write = require('write');
const path = require('path');
function CreateFilePlugin(options){
if (options === void 0) {
throw new Error(`Please provide 'options' for the CreateFilePlugin config`);
}
if (options.path == null) {
throw new Error(`Please provide 'options.path' in the CreateFilePlugin config`);
}
if (options.fileName == null) {
throw new Error(`Please provide 'options.fileName' in the CreateFilePlugin config`);
}
if (options.content == null) {
throw new Error(`Please provide 'options.content' in the CreateFilePlugin config`);
}
this.options = options;
}
function _createFile(filePath, fileName, content) {
return () => {
const fullPath = path.join(filePath, fileName);
const contentData = typeof content === 'function' ? content(filePath, fileName) : content;
write.sync(fullPath, contentData);
}
}
CreateFilePlugin.prototype.apply = function (compiler) {
const createFile = () => _createFile(this.options.path, this.options.fileName, this.options.content);
if (!!compiler.hooks) {
compiler.hooks.done.tap('CreateFileWebpack', createFile());
} else {
compiler.plugin('done', createFile());
}
};
return CreateFilePlugin;
})();
module.exports = CreateFilePlugin;