-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
41 lines (35 loc) · 865 Bytes
/
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
const path = require('path');
const weblog = require('webpack-log');
const rimraf = require('rimraf');
const version = require('./package.json').version;
const PluginName = 'Clean After Emit Webpack Plguin';
const log = weblog({name: PluginName});
function isAbsolutePath (userPath) {
return path.isAbsolute(userPath);
}
function rm(paths){
if (!Array.isArray(paths)) return;
paths.forEach(p => {
if (!isAbsolutePath(p)) return;
rimraf.sync(p);
log.info(`remove ${p} after build`);
})
}
module.exports = class CleanAfterEmitWebpackPlguin {
constructor({
paths = [],
}) {
this.paths = paths;
this.version = version;
this.PluginName = PluginName;
}
apply(compiler) {
compiler.hooks.afterEmit.tapAsync(
this.PluginName,
(compilation, cb) => {
rm(this.paths);
cb();
}
)
}
};