-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
76 lines (66 loc) · 2.23 KB
/
build.js
File metadata and controls
76 lines (66 loc) · 2.23 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
const fs = require('fs');
const esbuild = require('esbuild');
const path = require('path');
function base64Encode(file) {
const bitmap = fs.readFileSync(file);
return Buffer.from(bitmap).toString('base64');
}
async function build() {
// 1. Bundle React App
const result = await esbuild.build({
entryPoints: ['src/index.js'],
bundle: true,
minify: true,
loader: { '.js': 'jsx' },
write: false,
});
const appCode = result.outputFiles[0].text;
// 2. Leaflet CSS and Images
let leafletCSS = fs.readFileSync('src/lib/leaflet.css', 'utf8');
// Replace image URLs with base64
const images = ['layers.png', 'layers-2x.png', 'marker-icon.png'];
images.forEach(img => {
if (fs.existsSync(`src/lib/images/${img}`)) {
const b64 = base64Encode(`src/lib/images/${img}`);
const ext = path.extname(img).substring(1);
const dataURI = `data:image/${ext};base64,${b64}`;
leafletCSS = leafletCSS.replace(new RegExp(`images/${img}`, 'g'), dataURI);
}
});
// Tailwind
const tailwindScript = fs.readFileSync('src/lib/tailwind.js', 'utf8');
// HTML Template
const html = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Passive Radar Lab</title>
<style>
${leafletCSS}
body, html { margin: 0; padding: 0; height: 100%; overflow: hidden; background-color: #0f172a; }
#root { height: 100%; width: 100%; }
.leaflet-container { background: #000 !important; }
.custom-div-icon { background: transparent; border: none; }
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: #1e293b; }
::-webkit-scrollbar-thumb { background: #475569; border-radius: 3px; }
</style>
<script>
${tailwindScript}
</script>
</head>
<body>
<div id="root"></div>
<script>
${appCode}
</script>
</body>
</html>`;
fs.writeFileSync('PRSim_bundled.html', html);
console.log('Build complete: PRSim_bundled.html');
}
build().catch(e => {
console.error(e);
process.exit(1);
});