@sprout2000/esbuild-copy-plugin
Version:
An esbuild plugin to efficiently copy static files from a source directory to a destination directory
53 lines (44 loc) • 2.56 kB
JavaScript
var $jFOtf$nodecrypto = require("node:crypto");
var $jFOtf$nodefs = require("node:fs");
function $parcel$interopDefault(a) {
return a && a.__esModule ? a.default : a;
}
function $parcel$export(e, n, v, s) {
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
}
$parcel$export(module.exports, "getDigest", () => $97cd11974a512e8c$export$db1db425883506a0);
$parcel$export(module.exports, "getFileDigest", () => $97cd11974a512e8c$export$f850894d0b17ae9d);
$parcel$export(module.exports, "filter", () => $97cd11974a512e8c$export$3dea766d36a8935f);
$parcel$export(module.exports, "copyPlugin", () => $97cd11974a512e8c$export$b979b7f816ac7b25);
const $97cd11974a512e8c$export$db1db425883506a0 = (string)=>{
const hash = (0, ($parcel$interopDefault($jFOtf$nodecrypto))).createHash("md5");
const data = hash.update(string, "utf-8");
return data.digest("hex");
};
const $97cd11974a512e8c$export$f850894d0b17ae9d = (path)=>{
if (!(0, ($parcel$interopDefault($jFOtf$nodefs))).existsSync(path)) return null;
if ((0, ($parcel$interopDefault($jFOtf$nodefs))).statSync(path).isDirectory()) return null;
return $97cd11974a512e8c$export$db1db425883506a0((0, ($parcel$interopDefault($jFOtf$nodefs))).readFileSync(path).toString());
};
const $97cd11974a512e8c$export$3dea766d36a8935f = (src, dest)=>{
if (!(0, ($parcel$interopDefault($jFOtf$nodefs))).existsSync(dest)) return true;
if ((0, ($parcel$interopDefault($jFOtf$nodefs))).statSync(dest).isDirectory()) return true;
return $97cd11974a512e8c$export$f850894d0b17ae9d(src) !== $97cd11974a512e8c$export$f850894d0b17ae9d(dest);
};
const $97cd11974a512e8c$export$b979b7f816ac7b25 = (options = {})=>({
name: "esbuild-copy-plugin",
setup (build) {
const src = options.src || "./assets";
const dest = options.dest || "./dist";
build.onEnd(()=>// https://nodejs.org/dist/latest-v18.x/docs/api/fs.html
(0, ($parcel$interopDefault($jFOtf$nodefs))).cpSync(src, dest, {
dereference: options.dereference || false,
errorOnExist: options.errorOnExist || false,
filter: options.filter || $97cd11974a512e8c$export$3dea766d36a8935f,
force: options.force || true,
preserveTimestamps: options.preserveTimestamps || false,
recursive: options.recursive || true,
verbatimSymlinks: options.verbatimSymlinks || false
}));
}
});