forked from cesium-plugin/cesium-heatmap-es6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebapck-plugin-copy.js
71 lines (66 loc) · 2.32 KB
/
webapck-plugin-copy.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const fs = require("fs-extra");
let paths = []
class CopyDirWebpackPlugin {
constructor(options) {
if (!Array.isArray(options)) {
options = [options];
}
this.options = options;
}
getOptions(skipts) {
if (skipts) {
return {
filter: (src) => {
if (fs.lstatSync(src).isDirectory()) {
return true;
} else {
paths.push(src)
return src.indexOf(".ts") < 0
}
}
}
} else {
return {}
}
}
apply(compiler) {
const opts = this.options;
compiler.hooks.done.tap(
'Copy Plugin',
(
stats /* stats is passed as an argument when done hook is tapped. */
) => {
opts.forEach(opt => {
fs.copy(
opt.from,
opt.to,
this.getOptions(opt.skipts)
).then(res => {
console.log(`完成 copy ${opt.from} to ${opt.to} ${JSON.stringify(res)}`);
if (opt.skipts) {
//把打包生成js删除
paths.forEach((src) => {
if (src.indexOf(".js") > -1) {
//源码为js的跳过
let find = false
if (opt.skipjs) {
find = opt.skipjs.find((str) => {
return src.indexOf(str) > -1
})
}
if (!find)
fs.remove(src, err => {
if (err) return console.error(err)
console.log(src, 'remove success!')
})
}
})
paths = []
}
})
})
}
);
}
}
module.exports = CopyDirWebpackPlugin;