2021-04-04 20:48:18 +08:00

32 lines
844 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const Fs = require("fs");
const Path = require("path");
const FsExtra = require("fs-extra");
class Copy {
constructor(options) {
this.options = options;
}
apply(compiler) {
compiler.plugin("done", (compilation, callback) => {
const cfg = this.options;
if (cfg && cfg.length > 0) {
cfg.forEach(({src, dest}) => {
let fullSrc = Path.join(compilation.compilation.options.context, src);
if (Fs.existsSync(fullSrc)) {
let distPath = compilation.compilation.options.output.path;
let outFile = Path.join(distPath, dest);
FsExtra.ensureFileSync(outFile);
FsExtra.copyFileSync(fullSrc, outFile);
} else {
console.error(`manifest文件不存在${src}`);
}
});
}
});
}
}
module.exports = Copy;