代码拉取完成,页面将自动刷新
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;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。