-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProcessControlPlugin.js
More file actions
31 lines (27 loc) · 1004 Bytes
/
ProcessControlPlugin.js
File metadata and controls
31 lines (27 loc) · 1004 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
const fs = require("fs");
const path = require("path");
let CustomPlugin = function(options) {
options = options || {};
this.options = options;
};
CustomPlugin.prototype.apply = function(compiler) {
// 如果希望在生成的资源输出到output指定目录之前执行某个功能
compiler.hooks.emit.tap("ProcessControl", () => {});
// 编译完成之后
compiler.hooks.done.tap("ProcessControl", () => {
// 执行一次图片封装解析
var sourceFile = path.join(__dirname, "outputDir/index.html");
var destPath = path.join(__dirname, "dist", "index.html");
var readStream = fs.createReadStream(sourceFile);
var writeStream = fs.createWriteStream(destPath);
readStream.pipe(writeStream);
console.log("move done");
try {
fs.unlinkSync("outputDir/index.html");
//file removed
} catch (err) {
console.error(err);
}
});
};
module.exports = CustomPlugin;