-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
66 lines (59 loc) · 1.87 KB
/
Copy pathbuild.js
File metadata and controls
66 lines (59 loc) · 1.87 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
/**
* Build script for watcher.js bundle
*
* Usage:
* node build.js - Build minified production bundle
* node build.js --watch - Watch mode (rebuilds on changes)
* node build.js --dev - Development build with sourcemaps (local use only)
*
* Note: FPP auto-loads ALL .js files in the js/ directory, so we only build
* watcher.min.js to avoid duplicate loading. Use --dev locally for debugging.
*/
const esbuild = require('esbuild');
const isWatch = process.argv.includes('--watch');
const isDev = process.argv.includes('--dev');
const common = {
entryPoints: ['js/src/index.js'],
bundle: true,
target: ['es2018'], // Good browser support
format: 'iife', // Self-executing for browser
globalName: 'Watcher',
};
async function build() {
try {
// Production build (always created)
const prodOptions = {
...common,
outfile: 'js/watcher.min.js',
minify: true,
sourcemap: false,
};
// Development build (local use only - not committed)
const devOptions = {
...common,
outfile: 'js/watcher.dev.js',
sourcemap: true,
};
if (isWatch) {
// Watch mode - production build
const ctx = await esbuild.context(prodOptions);
await ctx.watch();
console.log('Watching for changes... (output: js/watcher.min.js)');
} else if (isDev) {
// Development build with sourcemaps
await esbuild.build(devOptions);
console.log('Development build complete:');
console.log(' - js/watcher.dev.js (with sourcemaps)');
console.log('Note: This file is for local debugging only. Do not commit.');
} else {
// Standard production build
await esbuild.build(prodOptions);
console.log('Build complete:');
console.log(' - js/watcher.min.js');
}
} catch (error) {
console.error('Build failed:', error);
process.exit(1);
}
}
build();