-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
142 lines (130 loc) · 3.78 KB
/
Copy pathbuild.js
File metadata and controls
142 lines (130 loc) · 3.78 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import { build } from 'esbuild';
import { readdirSync, readFileSync, writeFileSync } from 'node:fs';
import { createHash } from 'node:crypto';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
const __dirname = dirname(fileURLToPath(import.meta.url));
const isProd = process.env.NODE_ENV === 'production';
// Vendor bundle: Tabler JS + SweetAlert2
await build({
entryPoints: ['src/vendor.js'],
bundle: true,
outfile: 'public/js/vendor.js',
format: 'esm',
platform: 'browser',
target: ['es2020'],
define: {
global: 'globalThis',
},
minify: isProd,
sourcemap: !isProd,
});
console.log('Vendor built → public/js/vendor.js');
// Authenticated app vendor CSS: Tabler + supporting controls
await build({
entryPoints: ['src/admin_vendor.css'],
bundle: true,
outfile: 'public/css/admin_vendor.css',
platform: 'browser',
minify: isProd,
sourcemap: !isProd,
loader: {
'.woff': 'file',
'.woff2': 'file',
'.ttf': 'file',
'.eot': 'file',
'.svg': 'file',
},
});
console.log('Admin vendor CSS built → public/css/admin_vendor.css');
// TipTap Editor
await build({
entryPoints: ['src/editor/note_editor.js'],
bundle: true,
outfile: 'public/js/editor.js',
format: 'esm',
platform: 'browser',
target: ['es2020'],
minify: isProd,
sourcemap: !isProd,
});
console.log('Editor built → public/js/editor.js');
// Cytoscape Graph (lazy-loaded on /graph page only)
await build({
entryPoints: ['src/graph/graph_bundle.js'],
bundle: true,
outfile: 'public/js/graph_bundle.js',
format: 'esm',
platform: 'browser',
target: ['es2020'],
minify: isProd,
sourcemap: !isProd,
});
console.log('Graph bundle built → public/js/graph_bundle.js');
// iframe-resizer parent/child bundles for sandboxed email HTML iframes
await build({
entryPoints: ['src/iframe_resizer_parent.js'],
bundle: true,
outfile: 'public/js/iframe_resizer_parent.js',
format: 'iife',
platform: 'browser',
target: ['es2020'],
minify: isProd,
sourcemap: false,
});
console.log('iframe-resizer parent built → public/js/iframe_resizer_parent.js');
await build({
entryPoints: ['src/iframe_resizer_child.js'],
bundle: true,
outfile: 'public/js/iframe_resizer_child.js',
format: 'iife',
platform: 'browser',
target: ['es2020'],
minify: isProd,
sourcemap: false,
});
console.log('iframe-resizer child built → public/js/iframe_resizer_child.js');
await build({
entryPoints: ['src/email_dark_mode_child.js'],
bundle: true,
outfile: 'public/js/email_dark_mode_child.js',
format: 'iife',
platform: 'browser',
target: ['es2020'],
minify: isProd,
sourcemap: false,
});
console.log('Email dark mode child built → public/js/email_dark_mode_child.js');
await build({
entryPoints: ['src/email_quote_collapse_child.js'],
bundle: true,
outfile: 'public/js/email_quote_collapse_child.js',
format: 'iife',
platform: 'browser',
target: ['es2020'],
minify: isProd,
sourcemap: false,
});
console.log('Email quote collapse child built → public/js/email_quote_collapse_child.js');
await build({
entryPoints: ['src/email_iframe_renderer.js'],
bundle: true,
outfile: 'public/js/email_iframe_renderer.js',
format: 'iife',
platform: 'browser',
target: ['es2020'],
minify: isProd,
sourcemap: false,
});
console.log('Email iframe renderer built → public/js/email_iframe_renderer.js');
// Generate build ID from content hash of all static JS + CSS assets
const hash = createHash('md5');
for (const dir of ['public/js', 'public/css']) {
for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
if (entry.isFile()) hash.update(readFileSync(join(dir, entry.name)));
}
}
const buildId = hash.digest('hex').slice(0, 10);
writeFileSync(join(__dirname, 'public', 'build-id'), buildId);
console.log(`Build ID: ${buildId}`);
console.log('Build complete.');