jsgui3-server 0.0.138 → 0.0.140
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +87 -0
- package/README.md +12 -0
- package/docs/GUIDE_TO_AGENTIC_WORKFLOWS_BY_GROK.md +19 -0
- package/docs/advanced-usage-examples.md +1360 -0
- package/docs/agent-development-guide.md +386 -0
- package/docs/api-reference.md +916 -0
- package/docs/broken-functionality-tracker.md +285 -0
- package/docs/bundling-system-deep-dive.md +525 -0
- package/docs/cli-reference.md +393 -0
- package/docs/comprehensive-documentation.md +1403 -0
- package/docs/configuration-reference.md +808 -0
- package/docs/controls-development.md +859 -0
- package/docs/documentation-review/CURRENT_REVIEW.md +95 -0
- package/docs/function-publishers-json-apis.md +847 -0
- package/docs/getting-started-with-json.md +518 -0
- package/docs/minification-compression-sourcemaps-status.md +482 -0
- package/docs/minification-compression-sourcemaps-test-results.md +205 -0
- package/docs/publishers-guide.md +313 -0
- package/docs/resources-guide.md +615 -0
- package/docs/serve-helpers.md +406 -0
- package/docs/simple-server-api-design.md +13 -0
- package/docs/system-architecture.md +275 -0
- package/docs/troubleshooting.md +698 -0
- package/examples/json/README.md +115 -0
- package/examples/json/basic-api/README.md +345 -0
- package/examples/json/basic-api/server.js +199 -0
- package/examples/json/simple-api/README.md +125 -0
- package/examples/json/simple-api/diagnostic-report.json +73 -0
- package/examples/json/simple-api/diagnostic-test.js +433 -0
- package/examples/json/simple-api/server-debug.md +58 -0
- package/examples/json/simple-api/server.js +91 -0
- package/examples/json/simple-api/test.js +215 -0
- package/http/responders/static/Static_Route_HTTP_Responder.js +1 -2
- package/package.json +19 -8
- package/publishers/helpers/assigners/static-compressed-response-buffers/Single_Control_Webpage_Server_Static_Compressed_Response_Buffers_Assigner.js +65 -12
- package/publishers/helpers/preparers/static/bundle/Static_Routes_Responses_Webpage_Bundle_Preparer.js +6 -1
- package/publishers/http-function-publisher.js +59 -38
- package/publishers/http-webpage-publisher.js +48 -1
- package/resources/processors/bundlers/js/esbuild/Advanced_JS_Bundler_Using_ESBuild.js +38 -146
- package/resources/processors/bundlers/js/esbuild/Core_JS_Non_Minifying_Bundler_Using_ESBuild.js +54 -5
- package/resources/processors/bundlers/js/esbuild/Core_JS_Single_File_Minifying_Bundler_Using_ESBuild.js +36 -4
- package/serve-factory.js +36 -9
- package/server.js +10 -4
- package/test-report.json +0 -0
- package/tests/README.md +250 -0
- package/tests/assigners.test.js +316 -0
- package/tests/bundlers.test.js +329 -0
- package/tests/configuration-validation.test.js +530 -0
- package/tests/content-analysis.test.js +641 -0
- package/tests/end-to-end.test.js +496 -0
- package/tests/error-handling.test.js +746 -0
- package/tests/performance.test.js +653 -0
- package/tests/publishers.test.js +395 -0
- package/tests/temp_invalid.js +7 -0
- package/tests/temp_invalid_utf8.js +1 -0
- package/tests/temp_malformed.js +10 -0
- package/tests/test-runner.js +261 -0
|
@@ -0,0 +1,525 @@
|
|
|
1
|
+
# Bundling System Deep Dive
|
|
2
|
+
|
|
3
|
+
## When to Read
|
|
4
|
+
|
|
5
|
+
This document provides detailed technical documentation of JSGUI3 Server's bundling system. Read this when:
|
|
6
|
+
- You need to understand how JavaScript and CSS bundling works internally
|
|
7
|
+
- You're debugging bundling issues or performance problems
|
|
8
|
+
- You want to extend or modify the bundling system
|
|
9
|
+
- You're implementing custom bundlers or build processes
|
|
10
|
+
- You need to optimize bundle size or loading performance
|
|
11
|
+
|
|
12
|
+
**Note:** For basic usage, see [README.md](../README.md). For configuration options, see [docs/configuration-reference.md](docs/configuration-reference.md).
|
|
13
|
+
|
|
14
|
+
## Overview
|
|
15
|
+
|
|
16
|
+
JSGUI3 Server uses a sophisticated multi-stage bundling system that:
|
|
17
|
+
|
|
18
|
+
1. **Extracts CSS** from control class definitions
|
|
19
|
+
2. **Bundles JavaScript** using ESBuild
|
|
20
|
+
3. **Combines assets** into optimized bundles
|
|
21
|
+
4. **Serves content** with proper caching and MIME types
|
|
22
|
+
|
|
23
|
+
The system is designed to handle the unique requirements of JSGUI3's component-based architecture where CSS is defined as static properties on control classes.
|
|
24
|
+
|
|
25
|
+
## Architecture Overview
|
|
26
|
+
|
|
27
|
+
### Key Components
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
Bundling Flow:
|
|
31
|
+
Control Classes → CSS Extraction → JS Bundling → Asset Serving
|
|
32
|
+
↓ ↓ ↓ ↓
|
|
33
|
+
MyControl.css → extractCSS() → bundleJS() → HTTP Response
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
#### Core Classes
|
|
37
|
+
- **Advanced_JS_Bundler_Using_ESBuild**: Main bundler orchestrating the process
|
|
38
|
+
- **Core_JS_Non_Minifying_Bundler_Using_ESBuild**: Handles JS bundling without minification
|
|
39
|
+
- **Core_JS_Single_File_Minifying_Bundler_Using_ESBuild**: Handles minified JS bundling
|
|
40
|
+
- **CSS_And_JS_From_JS_String_Extractor**: Extracts CSS from bundled JavaScript
|
|
41
|
+
|
|
42
|
+
#### Process Flow
|
|
43
|
+
1. **Input**: Control classes with static `.css` properties
|
|
44
|
+
2. **Stage 1**: Non-minifying JS bundle created
|
|
45
|
+
3. **Stage 2**: CSS extracted from the bundle
|
|
46
|
+
4. **Stage 3**: Clean JS bundle (without CSS) created
|
|
47
|
+
5. **Stage 4**: JS optionally minified
|
|
48
|
+
6. **Stage 5**: Final bundles served with proper routes
|
|
49
|
+
|
|
50
|
+
## Detailed Process Flow
|
|
51
|
+
|
|
52
|
+
### Stage 1: Initial JS Bundling
|
|
53
|
+
|
|
54
|
+
```javascript
|
|
55
|
+
// From Advanced_JS_Bundler_Using_ESBuild.bundle()
|
|
56
|
+
const non_minifying_bundle = await this.non_minifying_bundler.bundle(js_file_path);
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
**What happens:**
|
|
60
|
+
- ESBuild processes the input JavaScript file
|
|
61
|
+
- Resolves all `require()` and `import` statements
|
|
62
|
+
- Includes CSS as string literals in the bundle
|
|
63
|
+
- Produces a single JavaScript file with all dependencies
|
|
64
|
+
|
|
65
|
+
**Output format:**
|
|
66
|
+
```javascript
|
|
67
|
+
// Bundle contains both JS and CSS as strings
|
|
68
|
+
const bundle = {
|
|
69
|
+
_arr: [{
|
|
70
|
+
type: 'JavaScript',
|
|
71
|
+
extension: 'js',
|
|
72
|
+
text: '/* bundled JS with CSS strings */'
|
|
73
|
+
}]
|
|
74
|
+
};
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Stage 2: CSS Extraction
|
|
78
|
+
|
|
79
|
+
```javascript
|
|
80
|
+
// CSS extraction from the bundle
|
|
81
|
+
const extracted = await this.css_and_js_from_js_string_extractor.prepare(bundle);
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
**CSS Extraction Process:**
|
|
85
|
+
1. **Parse JavaScript**: AST analysis of the bundled code
|
|
86
|
+
2. **Find CSS Assignments**: Locate `ControlClass.css = '...'` patterns
|
|
87
|
+
3. **Extract Strings**: Pull CSS content from string literals
|
|
88
|
+
4. **Concatenate**: Combine all CSS into single stylesheet
|
|
89
|
+
|
|
90
|
+
**Technical Details:**
|
|
91
|
+
- Uses Babel AST parsing to analyze code structure
|
|
92
|
+
- Handles template literals and string concatenation
|
|
93
|
+
- Preserves CSS comments and formatting
|
|
94
|
+
- Maintains source mapping information
|
|
95
|
+
|
|
96
|
+
### Stage 3: Clean JS Bundle
|
|
97
|
+
|
|
98
|
+
```javascript
|
|
99
|
+
// Create JS bundle without CSS
|
|
100
|
+
const clean_js_bundle = await this.non_minifying_bundler.bundle(js_file_path);
|
|
101
|
+
// (CSS extraction logic removes CSS from this bundle)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
**Process:**
|
|
105
|
+
- Re-bundle JavaScript without CSS content
|
|
106
|
+
- Ensures clean separation between code and styles
|
|
107
|
+
- Prepares for optional minification
|
|
108
|
+
|
|
109
|
+
### Stage 4: Minification (Optional)
|
|
110
|
+
|
|
111
|
+
```javascript
|
|
112
|
+
// Only in production/debug=false mode
|
|
113
|
+
if (!this.debug) {
|
|
114
|
+
const minified = await this.minifying_bundler.bundle(clean_js_file);
|
|
115
|
+
// Apply minification transforms
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
**Minification Features:**
|
|
120
|
+
- Variable name shortening
|
|
121
|
+
- Dead code elimination
|
|
122
|
+
- Whitespace removal
|
|
123
|
+
- Comment stripping
|
|
124
|
+
- Source map generation (in debug mode)
|
|
125
|
+
|
|
126
|
+
### Stage 5: Route Registration
|
|
127
|
+
|
|
128
|
+
```javascript
|
|
129
|
+
// From HTTP_Webpage_Publisher
|
|
130
|
+
for (const item of bundle._arr) {
|
|
131
|
+
const responder = new Static_Route_HTTP_Responder(item);
|
|
132
|
+
server.router.set_route(item.route, responder, responder.handle_http);
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
**Route Mapping:**
|
|
137
|
+
- `/js/js.js` → Bundled JavaScript
|
|
138
|
+
- `/css/css.css` → Extracted CSS
|
|
139
|
+
- `/` → Main HTML page
|
|
140
|
+
|
|
141
|
+
## CSS Extraction Deep Dive
|
|
142
|
+
|
|
143
|
+
### How CSS Extraction Works
|
|
144
|
+
|
|
145
|
+
The CSS extraction system analyzes JavaScript code to find CSS definitions:
|
|
146
|
+
|
|
147
|
+
```javascript
|
|
148
|
+
// Input: Control definition
|
|
149
|
+
class MyControl extends Active_HTML_Document {
|
|
150
|
+
// ... constructor logic
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
MyControl.css = `
|
|
154
|
+
.my-control {
|
|
155
|
+
background: #f0f0f0;
|
|
156
|
+
padding: 20px;
|
|
157
|
+
}
|
|
158
|
+
`;
|
|
159
|
+
|
|
160
|
+
// Output: Extracted CSS served at /css/css.css
|
|
161
|
+
.my-control {
|
|
162
|
+
background: #f0f0f0;
|
|
163
|
+
padding: 20px;
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### AST Analysis Process
|
|
168
|
+
|
|
169
|
+
1. **Parse JavaScript** using Babel parser
|
|
170
|
+
2. **Traverse AST** looking for assignment expressions
|
|
171
|
+
3. **Identify Patterns**:
|
|
172
|
+
- `ClassName.css = "..."` (string literal)
|
|
173
|
+
- `ClassName.css = `...`` (template literal)
|
|
174
|
+
- `ClassName.css = var + "..."` (concatenation)
|
|
175
|
+
4. **Extract Content** from string/template literals
|
|
176
|
+
5. **Concatenate** all found CSS into single stylesheet
|
|
177
|
+
|
|
178
|
+
### Edge Cases Handled
|
|
179
|
+
|
|
180
|
+
- **Template Literals**: Preserves interpolation and multi-line formatting
|
|
181
|
+
- **String Concatenation**: Handles `css += "..."` patterns
|
|
182
|
+
- **Multiple Classes**: Combines CSS from all control classes
|
|
183
|
+
- **Inheritance**: Includes CSS from parent classes
|
|
184
|
+
- **Dynamic CSS**: Handles runtime CSS generation (limited)
|
|
185
|
+
|
|
186
|
+
## ESBuild Integration
|
|
187
|
+
|
|
188
|
+
### Configuration
|
|
189
|
+
|
|
190
|
+
```javascript
|
|
191
|
+
// Typical ESBuild config used internally
|
|
192
|
+
{
|
|
193
|
+
entryPoints: [inputFile],
|
|
194
|
+
bundle: true,
|
|
195
|
+
format: 'iife', // Immediately Invoked Function Expression
|
|
196
|
+
globalName: 'jsgui',
|
|
197
|
+
sourcemap: debug ? 'inline' : false,
|
|
198
|
+
minify: false, // Handled separately
|
|
199
|
+
external: [], // No externals for full bundling
|
|
200
|
+
target: 'es2018'
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### Why ESBuild?
|
|
205
|
+
|
|
206
|
+
- **Fast**: Written in Go, significantly faster than alternatives
|
|
207
|
+
- **Modern**: Native ES module support, tree shaking
|
|
208
|
+
- **Flexible**: Supports multiple output formats
|
|
209
|
+
- **Reliable**: Battle-tested in production environments
|
|
210
|
+
- **Small**: Minimal dependencies
|
|
211
|
+
|
|
212
|
+
### Bundle Output Format
|
|
213
|
+
|
|
214
|
+
ESBuild produces JavaScript that can run in browsers:
|
|
215
|
+
|
|
216
|
+
```javascript
|
|
217
|
+
// IIFE format wraps everything in a function
|
|
218
|
+
(function() {
|
|
219
|
+
// Bundled code here
|
|
220
|
+
var jsgui = {};
|
|
221
|
+
// ... all dependencies included
|
|
222
|
+
})();
|
|
223
|
+
|
|
224
|
+
// Global assignment makes it available
|
|
225
|
+
window.jsgui = jsgui;
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
## Performance Characteristics
|
|
229
|
+
|
|
230
|
+
### Timing Breakdown
|
|
231
|
+
|
|
232
|
+
- **CSS Extraction**: 50-200ms (depends on code size)
|
|
233
|
+
- **JS Bundling**: 100-500ms (ESBuild is very fast)
|
|
234
|
+
- **Minification**: 50-200ms (additional pass)
|
|
235
|
+
- **Total**: 200-900ms for first bundle
|
|
236
|
+
|
|
237
|
+
### Caching Strategy
|
|
238
|
+
|
|
239
|
+
- **Development**: No caching, rebuild on every request
|
|
240
|
+
- **Production**: Cache bundles until server restart
|
|
241
|
+
- **Invalidation**: Manual restart required for changes
|
|
242
|
+
|
|
243
|
+
### Memory Usage
|
|
244
|
+
|
|
245
|
+
- **Base**: ~50MB for ESBuild process
|
|
246
|
+
- **Per Bundle**: +10-50MB depending on dependencies
|
|
247
|
+
- **CSS Extraction**: Additional AST parsing overhead
|
|
248
|
+
|
|
249
|
+
## Error Handling
|
|
250
|
+
|
|
251
|
+
### Common Errors
|
|
252
|
+
|
|
253
|
+
#### ESBuild Failures
|
|
254
|
+
```
|
|
255
|
+
Error: Build failed with 1 error:
|
|
256
|
+
input.js:1:0: ERROR: Expected identifier but found "}"
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
**Causes:**
|
|
260
|
+
- Syntax errors in JavaScript
|
|
261
|
+
- Missing dependencies
|
|
262
|
+
- Invalid import paths
|
|
263
|
+
|
|
264
|
+
**Solutions:**
|
|
265
|
+
- Check syntax with `node -c file.js`
|
|
266
|
+
- Verify all `require()` paths exist
|
|
267
|
+
- Ensure dependencies are installed
|
|
268
|
+
|
|
269
|
+
#### CSS Extraction Failures
|
|
270
|
+
```
|
|
271
|
+
Error: Cannot extract CSS from malformed JavaScript
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
**Causes:**
|
|
275
|
+
- Invalid JavaScript syntax
|
|
276
|
+
- Malformed CSS assignments
|
|
277
|
+
- Dynamic CSS generation not supported
|
|
278
|
+
|
|
279
|
+
**Solutions:**
|
|
280
|
+
- Validate JavaScript syntax first
|
|
281
|
+
- Check CSS property assignments
|
|
282
|
+
- Use static CSS definitions
|
|
283
|
+
|
|
284
|
+
#### Bundle Size Issues
|
|
285
|
+
```
|
|
286
|
+
Error: Bundle exceeds size limit
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
**Causes:**
|
|
290
|
+
- Large dependencies included
|
|
291
|
+
- Missing tree shaking
|
|
292
|
+
- Inefficient imports
|
|
293
|
+
|
|
294
|
+
**Solutions:**
|
|
295
|
+
- Use selective imports: `import { specific } from 'large-lib'`
|
|
296
|
+
- Exclude unnecessary dependencies
|
|
297
|
+
- Consider code splitting
|
|
298
|
+
|
|
299
|
+
## Extension Points
|
|
300
|
+
|
|
301
|
+
### Custom Bundlers
|
|
302
|
+
|
|
303
|
+
```javascript
|
|
304
|
+
class CustomBundler extends Advanced_JS_Bundler_Using_ESBuild {
|
|
305
|
+
async bundle(js_file_path) {
|
|
306
|
+
// Custom pre-processing
|
|
307
|
+
const preprocessed = await this.preprocess(js_file_path);
|
|
308
|
+
|
|
309
|
+
// Call parent bundling
|
|
310
|
+
const bundle = await super.bundle(preprocessed);
|
|
311
|
+
|
|
312
|
+
// Custom post-processing
|
|
313
|
+
return this.postprocess(bundle);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
### Custom CSS Extractors
|
|
319
|
+
|
|
320
|
+
```javascript
|
|
321
|
+
class CustomCSSExtractor {
|
|
322
|
+
async extract(jsBundle) {
|
|
323
|
+
// Custom CSS extraction logic
|
|
324
|
+
// Return { css: string, js: string }
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
### Plugin System
|
|
330
|
+
|
|
331
|
+
```javascript
|
|
332
|
+
// Bundler plugins (conceptual)
|
|
333
|
+
const bundler = new Advanced_JS_Bundler_Using_ESBuild({
|
|
334
|
+
plugins: [
|
|
335
|
+
{
|
|
336
|
+
name: 'custom-css',
|
|
337
|
+
transform: (css) => transformCSS(css)
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
name: 'asset-optimization',
|
|
341
|
+
optimize: (bundle) => optimizeBundle(bundle)
|
|
342
|
+
}
|
|
343
|
+
]
|
|
344
|
+
});
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
## Debugging Bundling Issues
|
|
348
|
+
|
|
349
|
+
### Enable Debug Mode
|
|
350
|
+
|
|
351
|
+
```bash
|
|
352
|
+
JSGUI_DEBUG=1 node cli.js serve
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
**What this enables:**
|
|
356
|
+
- Source maps in bundles
|
|
357
|
+
- Verbose logging of bundling steps
|
|
358
|
+
- Non-minified output
|
|
359
|
+
- Detailed error messages
|
|
360
|
+
|
|
361
|
+
### Logging Points
|
|
362
|
+
|
|
363
|
+
Key logging locations in the code:
|
|
364
|
+
|
|
365
|
+
```javascript
|
|
366
|
+
// In Advanced_JS_Bundler_Using_ESBuild
|
|
367
|
+
console.log('Starting CSS extraction...');
|
|
368
|
+
console.log('CSS extracted, length:', css.length);
|
|
369
|
+
console.log('Starting JS bundling...');
|
|
370
|
+
console.log('Bundle complete, items:', bundle._arr.length);
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
### Inspect Bundle Content
|
|
374
|
+
|
|
375
|
+
```javascript
|
|
376
|
+
// Add temporary logging
|
|
377
|
+
webpage_publisher.on('ready', (bundle) => {
|
|
378
|
+
console.log('Bundle contents:');
|
|
379
|
+
bundle._arr.forEach((item, i) => {
|
|
380
|
+
console.log(`Item ${i}: ${item.type} (${item.text.length} chars)`);
|
|
381
|
+
if (item.type === 'JavaScript') {
|
|
382
|
+
console.log('First 200 chars:', item.text.substring(0, 200));
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
});
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
### Common Debug Scenarios
|
|
389
|
+
|
|
390
|
+
#### CSS Not Appearing
|
|
391
|
+
1. Check if CSS extraction completed
|
|
392
|
+
2. Verify `/css/css.css` route is registered
|
|
393
|
+
3. Inspect extracted CSS content
|
|
394
|
+
4. Check browser network tab for CSS request
|
|
395
|
+
|
|
396
|
+
#### JavaScript Errors
|
|
397
|
+
1. Enable source maps (debug mode)
|
|
398
|
+
2. Check browser console for errors
|
|
399
|
+
3. Verify bundle loaded correctly
|
|
400
|
+
4. Test with non-minified bundle
|
|
401
|
+
|
|
402
|
+
#### Bundle Size Issues
|
|
403
|
+
1. Analyze bundle content
|
|
404
|
+
2. Check for duplicate dependencies
|
|
405
|
+
3. Use ESBuild's analyze feature
|
|
406
|
+
4. Consider tree shaking configuration
|
|
407
|
+
|
|
408
|
+
## Optimization Techniques
|
|
409
|
+
|
|
410
|
+
### Bundle Splitting
|
|
411
|
+
|
|
412
|
+
```javascript
|
|
413
|
+
// Conceptual: Split large bundles
|
|
414
|
+
const bundler = new Advanced_JS_Bundler_Using_ESBuild({
|
|
415
|
+
split: {
|
|
416
|
+
vendor: ['jsgui3-client', 'jsgui3-html'],
|
|
417
|
+
app: ['./client.js']
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
### Lazy Loading
|
|
423
|
+
|
|
424
|
+
```javascript
|
|
425
|
+
// Dynamic imports for code splitting
|
|
426
|
+
const control = await import('./HeavyControl.js');
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
### Asset Optimization
|
|
430
|
+
|
|
431
|
+
- **Image optimization**: Compress images in bundles
|
|
432
|
+
- **Font subsetting**: Include only used characters
|
|
433
|
+
- **CSS purging**: Remove unused styles
|
|
434
|
+
- **Compression**: Gzip/Brotli compression
|
|
435
|
+
|
|
436
|
+
### Caching Headers
|
|
437
|
+
|
|
438
|
+
```javascript
|
|
439
|
+
// Set appropriate cache headers
|
|
440
|
+
res.setHeader('Cache-Control', 'public, max-age=31536000'); // 1 year
|
|
441
|
+
res.setHeader('ETag', generateETag(bundle));
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
## Migration and Compatibility
|
|
445
|
+
|
|
446
|
+
### Legacy Bundle Paths
|
|
447
|
+
|
|
448
|
+
**Issue**: Some code references old bundle paths
|
|
449
|
+
**Status**: Being cleaned up (see TODO items)
|
|
450
|
+
**Workaround**: Update references to use current paths
|
|
451
|
+
|
|
452
|
+
### ESBuild Version Compatibility
|
|
453
|
+
|
|
454
|
+
- **Current**: ESBuild v0.x
|
|
455
|
+
- **Future**: May upgrade to newer versions
|
|
456
|
+
- **Breaking Changes**: Monitor ESBuild changelog
|
|
457
|
+
|
|
458
|
+
### Browser Compatibility
|
|
459
|
+
|
|
460
|
+
- **Target**: ES2018 features
|
|
461
|
+
- **Polyfills**: Not included (assume modern browsers)
|
|
462
|
+
- **Fallback**: Consider transpilation for older browsers
|
|
463
|
+
|
|
464
|
+
## Future Enhancements
|
|
465
|
+
|
|
466
|
+
### Planned Improvements
|
|
467
|
+
|
|
468
|
+
1. **Hot Reload**: Automatic browser refresh on changes
|
|
469
|
+
2. **Code Splitting**: Dynamic imports and lazy loading
|
|
470
|
+
3. **Asset Optimization**: Image/font optimization
|
|
471
|
+
4. **Bundle Analysis**: Size and dependency visualization
|
|
472
|
+
5. **Parallel Processing**: Faster bundling with worker threads
|
|
473
|
+
|
|
474
|
+
### Research Areas
|
|
475
|
+
|
|
476
|
+
1. **Vite Integration**: Modern development server
|
|
477
|
+
2. **SWC Integration**: Faster alternative to ESBuild
|
|
478
|
+
3. **Webpack Compatibility**: Migration path for complex builds
|
|
479
|
+
4. **Micro-frontend Support**: Bundle splitting for MFAs
|
|
480
|
+
|
|
481
|
+
## Troubleshooting
|
|
482
|
+
|
|
483
|
+
### Quick Diagnosis
|
|
484
|
+
|
|
485
|
+
```bash
|
|
486
|
+
# Check if bundling completes
|
|
487
|
+
node -e "
|
|
488
|
+
const Server = require('./server');
|
|
489
|
+
Server.serve({debug: true}).then(() => {
|
|
490
|
+
console.log('Bundling successful');
|
|
491
|
+
}).catch(err => {
|
|
492
|
+
console.error('Bundling failed:', err);
|
|
493
|
+
});
|
|
494
|
+
"
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
### Performance Monitoring
|
|
498
|
+
|
|
499
|
+
```javascript
|
|
500
|
+
// Add timing to bundling
|
|
501
|
+
const start = Date.now();
|
|
502
|
+
const bundle = await bundler.bundle(file);
|
|
503
|
+
console.log(`Bundling took ${Date.now() - start}ms`);
|
|
504
|
+
```
|
|
505
|
+
|
|
506
|
+
### Memory Profiling
|
|
507
|
+
|
|
508
|
+
```bash
|
|
509
|
+
# Monitor Node.js memory usage
|
|
510
|
+
node --inspect cli.js serve
|
|
511
|
+
# Use Chrome DevTools Memory tab
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
## Conclusion
|
|
515
|
+
|
|
516
|
+
The JSGUI3 bundling system is a sophisticated pipeline that handles the unique challenges of component-based UI development. Understanding its architecture is crucial for debugging issues and implementing enhancements.
|
|
517
|
+
|
|
518
|
+
Key takeaways:
|
|
519
|
+
- **Multi-stage process**: CSS extraction → JS bundling → optimization
|
|
520
|
+
- **ESBuild core**: Fast, reliable JavaScript bundling
|
|
521
|
+
- **CSS as code**: Unique approach treating styles as static properties
|
|
522
|
+
- **Debugging**: Use debug mode and logging for troubleshooting
|
|
523
|
+
- **Performance**: Fast for development, optimizable for production
|
|
524
|
+
|
|
525
|
+
For issues not covered here, check the [troubleshooting guide](docs/troubleshooting.md) or create an issue in the repository.
|