-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
executable file
·88 lines (74 loc) · 2.34 KB
/
build.js
File metadata and controls
executable file
·88 lines (74 loc) · 2.34 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import esbuild from 'esbuild';
import fs from 'fs';
import path from 'path';
//const esbuild = require('esbuild');
//const fs = require('fs');
//const path = require('path');
const copyHbsPlugin = {
name: 'copy-hbs-recursive',
setup(build) {
build.onEnd(() => {
const srcDir = path.resolve(import.meta.dirname, 'src/views');
const distDir = path.resolve(import.meta.dirname, 'dist/views');
const copyRecursive = (src, dest) => {
if (!fs.existsSync(dest)) {
fs.mkdirSync(dest, {recursive: true});
}
const entries = fs.readdirSync(src, {withFileTypes: true});
for (const entry of entries) {
const srcPath = path.join(src, entry.name);
const destPath = path.join(dest, entry.name);
if (entry.isDirectory()) {
copyRecursive(srcPath, destPath);
} else if (entry.isFile() && entry.name.endsWith('.hbs')) {
fs.copyFileSync(srcPath, destPath);
}
}
};
copyRecursive(srcDir, distDir);
});
}
};
const copyCssPlugin = {
name: 'copy-css',
setup(build) {
build.onEnd(() => {
const srcDir = path.resolve(import.meta.dirname, 'src/styles');
const distDir = path.resolve(import.meta.dirname, 'dist/styles');
if (!fs.existsSync(distDir)) {
fs.mkdirSync(distDir, {recursive: true});
};
const files = fs.readdirSync(srcDir).filter(file => file.endsWith('.css'));
for (const file of files) {
fs.copyFileSync(path.join(srcDir, file), path.join(distDir, file));
}
});
}
};
const copyScriptsPlugin = {
name: 'copy-scripts',
setup(build) {
build.onEnd(() => {
const srcDir = path.resolve(import.meta.dirname, 'src/scripts');
const distDir = path.resolve(import.meta.dirname, 'dist/scripts');
if (!fs.existsSync(distDir)) {
fs.mkdirSync(distDir, {recursive: true});
};
const files = fs.readdirSync(srcDir).filter(file => file.endsWith('.mjs'));
for (const file of files) {
fs.copyFileSync(path.join(srcDir, file), path.join(distDir, file));
}
});
}
};
esbuild.build({
entryPoints: ['src/**/*.js'],
platform: 'node',
format: 'esm',
bundle: false,
outdir: 'dist',
metafile: false,
sourcemap: true,
minify: false,
plugins: [copyHbsPlugin, copyCssPlugin, copyScriptsPlugin],
});