zjk
2026-07-31 8665daa7aa863f96d0d8f27c167edae1efc38022
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
const fs = require("fs");
const path = require("path");
 
const root = path.resolve(__dirname, "..");
const dist = path.join(root, "dist");
const rootFiles = ["index.html"];
const directories = ["css", "js", "pages", "assets"];
 
function copyFile(source, target) {
  fs.mkdirSync(path.dirname(target), { recursive: true });
  fs.copyFileSync(source, target);
}
 
fs.rmSync(dist, { recursive: true, force: true });
rootFiles.forEach((file) => copyFile(path.join(root, file), path.join(dist, file)));
directories.forEach((directory) => copyDirectory(path.join(root, directory), path.join(dist, directory)));
 
console.log("Build output: " + dist);
 
function copyDirectory(source, target) {
  fs.readdirSync(source, { withFileTypes: true }).forEach((entry) => {
    const sourcePath = path.join(source, entry.name);
    const targetPath = path.join(target, entry.name);
    if (entry.isDirectory()) {
      copyDirectory(sourcePath, targetPath);
      return;
    }
    copyFile(sourcePath, targetPath);
  });
}