demobank-ui: avoid experimental nodejs API
This commit is contained in:
parent
321c1781d9
commit
402ecb1a14
@ -74,52 +74,14 @@ function git_hash() {
|
|||||||
|
|
||||||
// FIXME: Put this into some helper library.
|
// FIXME: Put this into some helper library.
|
||||||
function copyFilesPlugin(options) {
|
function copyFilesPlugin(options) {
|
||||||
const getDigest = (string) => {
|
|
||||||
const hash = crypto.createHash("md5");
|
|
||||||
const data = hash.update(string, "utf-8");
|
|
||||||
|
|
||||||
return data.digest("hex");
|
|
||||||
};
|
|
||||||
|
|
||||||
const getFileDigest = (path) => {
|
|
||||||
if (!fs.existsSync(path)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fs.statSync(path).isDirectory()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return getDigest(fs.readFileSync(path));
|
|
||||||
};
|
|
||||||
|
|
||||||
function filter(src, dest) {
|
|
||||||
if (!fs.existsSync(dest)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fs.statSync(dest).isDirectory()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return getFileDigest(src) !== getFileDigest(dest);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: "copy-files",
|
name: "copy-files",
|
||||||
setup(build) {
|
setup(build) {
|
||||||
let src = options.src || "./static";
|
build.onEnd(() => {
|
||||||
let dest = options.dest || "./dist";
|
for (const fop of options) {
|
||||||
build.onEnd(() =>
|
fs.copyFileSync(fop.src, fop.dest);
|
||||||
fs.cpSync(src, dest, {
|
}
|
||||||
dereference: options.dereference || true,
|
});
|
||||||
errorOnExist: options.errorOnExist || false,
|
|
||||||
filter: options.filter || filter,
|
|
||||||
force: options.force || true,
|
|
||||||
preserveTimestamps: options.preserveTimestamps || true,
|
|
||||||
recursive: options.recursive || true,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -147,10 +109,12 @@ export const buildConfig = {
|
|||||||
plugins: [
|
plugins: [
|
||||||
preactCompatPlugin,
|
preactCompatPlugin,
|
||||||
sassPlugin(),
|
sassPlugin(),
|
||||||
copyFilesPlugin({
|
copyFilesPlugin([
|
||||||
src: "static/index.html",
|
{
|
||||||
dest: "dist/index.html",
|
src: "static/index.html",
|
||||||
}),
|
dest: "dist/index.html",
|
||||||
|
},
|
||||||
|
]),
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user