@timber-js/app 0.2.0-alpha.15 → 0.2.0-alpha.16
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/dist/adapters/nitro.d.ts +17 -1
- package/dist/adapters/nitro.d.ts.map +1 -1
- package/dist/adapters/nitro.js +5 -5
- package/dist/adapters/nitro.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/adapters/nitro.ts +25 -4
- package/src/index.ts +7 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@timber-js/app",
|
|
3
|
-
"version": "0.2.0-alpha.
|
|
3
|
+
"version": "0.2.0-alpha.16",
|
|
4
4
|
"description": "Vite-native React framework for Cloudflare Workers — correct HTTP semantics, real status codes, pages that work without JavaScript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare-workers",
|
package/src/adapters/nitro.ts
CHANGED
|
@@ -149,6 +149,23 @@ export interface NitroAdapterOptions {
|
|
|
149
149
|
*/
|
|
150
150
|
preset?: NitroPreset;
|
|
151
151
|
|
|
152
|
+
/**
|
|
153
|
+
* Enable application-level gzip compression for HTML and RSC responses.
|
|
154
|
+
*
|
|
155
|
+
* When `true` (default), the origin compresses responses using the Web
|
|
156
|
+
* `CompressionStream` API. This is useful for self-hosted deployments
|
|
157
|
+
* where no reverse proxy or CDN handles compression.
|
|
158
|
+
*
|
|
159
|
+
* Set to `false` when deploying behind a reverse proxy (nginx, caddy)
|
|
160
|
+
* or CDN (Cloudflare, Fastly, Vercel) that compresses at the edge.
|
|
161
|
+
* Disabling origin compression saves CPU on the Node.js event loop —
|
|
162
|
+
* compressing 1MB+ streaming HTML responses takes 10-15ms of main
|
|
163
|
+
* thread time per request, directly reducing throughput under load.
|
|
164
|
+
*
|
|
165
|
+
* @default true
|
|
166
|
+
*/
|
|
167
|
+
compress?: boolean;
|
|
168
|
+
|
|
152
169
|
/**
|
|
153
170
|
* Additional Nitro configuration to merge into the generated config.
|
|
154
171
|
* Overrides default values for the selected preset.
|
|
@@ -176,6 +193,7 @@ export interface NitroAdapterOptions {
|
|
|
176
193
|
*/
|
|
177
194
|
export function nitro(options: NitroAdapterOptions = {}): TimberPlatformAdapter {
|
|
178
195
|
const preset = options.preset ?? 'node-server';
|
|
196
|
+
const compress = options.compress ?? true;
|
|
179
197
|
const presetConfig = PRESET_CONFIGS[preset];
|
|
180
198
|
const pendingPromises: Promise<unknown>[] = [];
|
|
181
199
|
|
|
@@ -229,7 +247,7 @@ export function nitro(options: NitroAdapterOptions = {}): TimberPlatformAdapter
|
|
|
229
247
|
}
|
|
230
248
|
|
|
231
249
|
// Generate the Nitro entry point (imports from ./rsc/ within nitro dir)
|
|
232
|
-
const entry = generateNitroEntry(buildDir, outDir, preset);
|
|
250
|
+
const entry = generateNitroEntry(buildDir, outDir, preset, compress);
|
|
233
251
|
await writeFile(join(outDir, 'entry.ts'), entry);
|
|
234
252
|
|
|
235
253
|
// Run the Nitro build to produce a production-ready server bundle.
|
|
@@ -273,6 +291,7 @@ export function generateNitroEntry(
|
|
|
273
291
|
buildDir: string,
|
|
274
292
|
outDir: string,
|
|
275
293
|
preset: NitroPreset,
|
|
294
|
+
compress = true,
|
|
276
295
|
hasManifestInit = false
|
|
277
296
|
): string {
|
|
278
297
|
// The RSC entry is the main request handler — it exports the fetch handler as default.
|
|
@@ -338,12 +357,14 @@ export function generateNitroEntry(
|
|
|
338
357
|
// Import runWithWaitUntil only when the preset supports it.
|
|
339
358
|
const waitUntilImport = supportsWaitUntil ? ', runWithWaitUntil' : '';
|
|
340
359
|
|
|
360
|
+
const compressImport = compress ? "import { compressResponse } from './_compress.mjs'\n" : '';
|
|
361
|
+
const compressCall = compress ? 'compressResponse(webRequest, webResponse)' : 'webResponse';
|
|
362
|
+
|
|
341
363
|
return `// Generated by @timber-js/app/adapters/nitro
|
|
342
364
|
// Do not edit — this file is regenerated on each build.
|
|
343
365
|
|
|
344
366
|
${manifestImport}import handler, { runWithEarlyHintsSender${waitUntilImport} } from '${serverEntryRelative}'
|
|
345
|
-
|
|
346
|
-
|
|
367
|
+
${compressImport}
|
|
347
368
|
// Set TIMBER_RUNTIME for instrumentation.ts conditional SDK initialization.
|
|
348
369
|
// See design/25-production-deployments.md §"TIMBER_RUNTIME".
|
|
349
370
|
process.env.TIMBER_RUNTIME = '${runtimeName}'
|
|
@@ -357,7 +378,7 @@ export default async function timberHandler(event) {
|
|
|
357
378
|
// h3 v2: event.req is the Web Request
|
|
358
379
|
const webRequest = event.req
|
|
359
380
|
${handlerCall}
|
|
360
|
-
return
|
|
381
|
+
return ${compressCall}
|
|
361
382
|
}
|
|
362
383
|
`;
|
|
363
384
|
}
|
package/src/index.ts
CHANGED
|
@@ -428,8 +428,13 @@ export function timber(config?: TimberUserConfig): PluginOption[] {
|
|
|
428
428
|
ssr: 'virtual:timber-ssr-entry',
|
|
429
429
|
client: 'virtual:timber-browser-entry',
|
|
430
430
|
},
|
|
431
|
-
//
|
|
432
|
-
//
|
|
431
|
+
// Group all client reference wrappers into a single chunk instead of
|
|
432
|
+
// creating one tiny file per "use client" module. Without this, each
|
|
433
|
+
// server chunk's client references become a separate entry point,
|
|
434
|
+
// producing many sub-500B wrapper files (e.g., 30-byte re-exports).
|
|
435
|
+
// A single group eliminates 10+ unnecessary HTTP requests.
|
|
436
|
+
// See design/27-chunking-strategy.md and TIM-440.
|
|
437
|
+
clientChunks: () => 'client-refs',
|
|
433
438
|
});
|
|
434
439
|
}
|
|
435
440
|
);
|