forked from sirdesai22/create-nue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
minify.js
executable file
·45 lines (36 loc) · 1016 Bytes
/
minify.js
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
/*
Minifies Nue JS files into a single JS file (nue.js)
Uses esbuild or Bun's internal minifier depending on the environment
*/
import { promises as fs } from 'node:fs'
import { join } from 'node:path'
export default async function () {
try {
let Bundler = process.isBun ? Bun : await import('esbuild')
await Bundler.build({
entryPoints: [join('node_modules', 'nuejs-core', 'src', 'nue.js')],
format: 'esm',
bundle: true,
outdir: 'www',
minify: true,
})
console.log(
'Minified Nue to www/nue.js with',
process.isBun ? 'Bun' : 'ESBuild'
)
} catch (e) {
console.log(
'No builder found (esbuild or Bun)',
'www/nue.js is not minified'
)
await copyNue()
}
// no bundler -> just copy
async function copyNue() {
const dir = join('node_modules', 'nuejs-core', 'src')
const files = await fs.readdir(dir)
for (const name of files) {
await fs.copyFile(join(dir, name), join('www', name))
}
}
}