astro-precompressor 1.0.1 → 1.2.0

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/README.md CHANGED
@@ -3,6 +3,11 @@
3
3
  An Astro integration that precompresses build output using Gzip, Brotli and,
4
4
  optionally, Zstandard.
5
5
 
6
+ [![Tests](https://github.com/jpc-ae/astro-precompressor/actions/workflows/test.yml/badge.svg)](https://github.com/jpc-ae/astro-precompressor/actions/workflows/test.yml)
7
+
8
+ [![Latest](https://img.shields.io/npm/v/astro-precompressor)](https://www.npmjs.com/package/astro-precompressor)
9
+ [![License](https://img.shields.io/github/license/jpc-ae/astro-precompressor)](LICENSE)
10
+
6
11
  `astro-precompressor` runs after Astro finishes building your project,
7
12
  generating compressed sidecar files alongside eligible output files for your
8
13
  server to use instead of on-the-fly compression. It uses incremental caching to
@@ -13,11 +18,11 @@ performance.
13
18
  > [!IMPORTANT] For this integration to be useful, your hosting environment must
14
19
  > be set up for serving precompressed sidecars. See
15
20
  > [Configuring Your Hosting Environment](#configuring-your-hosting-environment)
16
- > for details.
21
+ > for suggestions on how to do this.
17
22
 
18
23
  ## Quick Start
19
24
 
20
- Add the extension to your project with the `astro add` command.
25
+ Add the integration to your project with the `astro add` command.
21
26
 
22
27
  ```bash
23
28
  # npm
@@ -30,10 +35,9 @@ pnpm astro add astro-precompressor
30
35
  yarn astro add astro-precompressor
31
36
  ```
32
37
 
33
- This will install the module into your project, import the integration in your
34
- Astro config, and add it to the end of your integrations array. The next time
35
- you run your build, you should see the compression details at the end of your
36
- build output.
38
+ This will install the package, add the integration to your Astro configuration,
39
+ and place it at the end of your `integrations` array. The next time you run your
40
+ build, you should see compression statistics in your build output.
37
41
 
38
42
  ```bash
39
43
  generating precompressed files
@@ -62,16 +66,16 @@ offer caching or are too complicated to configure for common options like file
62
66
  filtering. They are also either restricted to node's zlib library or require
63
67
  command-line scripts.
64
68
 
65
- This package aims to provide a straightforward configuration without sacrificing
66
- performance or flexibility. The priority is faster builds and, more importantly,
67
- faster rebuilds. It also offers optional Zopfli for better gzip compression, and
68
- is open to adding other engines on request (please
69
+ This package aims to be straightforward without sacrificing performance or
70
+ flexibility. It offers optional Zopfli for better gzip compression as well as a
71
+ fallback engine for Zstandard on older Node.js builds. Support for other
72
+ compression engines can be added on request (please
69
73
  [open an issue](https://github.com/jpc-ae/astro-precompressor/issues) for any
70
- requests).
74
+ requests). Faster rebuilds using an incremental cache is the priority.
71
75
 
72
76
  ## Features
73
77
 
74
- - **Sane defaults:** Gzip and Brotli tuned for high compression, with
78
+ - **Sane defaults:** Gzip and Brotli tuned for high compression ratios, with
75
79
  incremental caching to avoid redundant processing; Zstandard off but available
76
80
  if needed.
77
81
  - **Highly configurable:** Fine-tune algorithm-specific compression settings,
@@ -86,8 +90,10 @@ requests).
86
90
  than their originals.
87
91
  - **Detailed logging:** Choose between a basic summary, per-file statistics
88
92
  similar to Astro's build logs, and detailed diagnostic output.
93
+ - **Legacy Node.js support:** Install the `zstd-napi` package into your project
94
+ for zstd compression on Node.js versions prior to v22.15.0.
89
95
 
90
- ## Installation
96
+ ## Manual Installation
91
97
 
92
98
  ```bash
93
99
  # npm
@@ -122,13 +128,13 @@ pnpm add -D node-zopfli-es
122
128
  yarn add -D node-zopfli-es
123
129
  ```
124
130
 
125
- > [!TIP] The default settings used by `astro-precompressor` have been tuned for
126
- > speed without sacrificing compression. Unless gzip output is not needed or
127
- > there is a compelling reason to avoid the extra dependency, installing
128
- > `node-zopfli-es` alongside `astro-precompressor` is highly recommended. See
129
- > the Gzip section under [Algorithms](#compression-algorithms) for more details.
131
+ > [!TIP] The default zopfli settings used by `astro-precompressor` have been
132
+ > tuned for speed without sacrificing compression. If smaller gzip files are a
133
+ > priority, installing `node-zopfli-es` alongside `astro-precompressor` is
134
+ > highly recommended. See the Gzip section under
135
+ > [Algorithms](#compression-algorithms) for more details.
130
136
 
131
- ## Usage
137
+ ### Usage
132
138
 
133
139
  Import the integration into your Astro configuration and add it as the last item
134
140
  of the integrations array.
@@ -155,14 +161,15 @@ export default defineConfig({
155
161
 
156
162
  The integration accepts an optional configuration object.
157
163
 
158
- | Option | Default | Description |
159
- | -------------------------- | ----------------------- | --------------------------------------------------------- |
160
- | `algorithms` | Gzip and Brotli enabled | Compression algorithms and settings |
161
- | `filters` | Built-in file types | Files eligible for compression |
162
- | `performance` | Automatic concurrency | Processing and caching behaviour |
163
- | `logLevel` | 2 | Logging verbosity |
164
- | `failOnError` | disabled | Whether compression failures stop the build |
165
- | `recompressOnConfigChange` | disabled | Whether changes to this configuration force recompression |
164
+ | Option | Default | Description |
165
+ | -------------------------- | ------------------------------------------------------- | --------------------------------------------------------- |
166
+ | `algorithms` | Gzip, Brotli enabled; Zstandard disabled | Compression algorithms and their settings |
167
+ | `performance` | System-derived concurrency; incremental caching enabled | Concurrency, incremental processing, and output behaviour |
168
+ | `cache` | Pruning enabled | Cache maintenance and pruning |
169
+ | `filters` | Built-in filetypes; 150-byte minimum | File eligibility and per-file algorithm selection |
170
+ | `logLevel` | 2 (diagnostics available) | Logging verbosity |
171
+ | `failOnError` | false | Whether compression errors fail the build |
172
+ | `recompressOnConfigChange` | false | Whether configuration changes trigger recompression |
166
173
 
167
174
  Any provided options will be merged with the defaults. For example, `gzip` will
168
175
  still be enabled with the configuration below.
@@ -173,11 +180,14 @@ precompressor({
173
180
  brotli: false,
174
181
  zstd: true,
175
182
  },
183
+ cache: {
184
+ prune: true,
185
+ },
176
186
  filters: {
177
187
  minSize: 1024,
178
188
  fileTypes: ['.html', '.css', '.js', '.svg', '.txt'],
179
- include: ['www/**'],
180
- exclude: ['**/*.env', '**/.*/**'],
189
+ include: ['www/**', { pattern: '**/*.svg', algorithms: ['brotli'] }],
190
+ exclude: ['**/*.env', '**/.*/**', { pattern: '**/*.css', algorithms: ['zstd'] }],
181
191
  },
182
192
  logLevel: 0,
183
193
  })
@@ -203,7 +213,7 @@ algorithms: {
203
213
  > [!NOTE] The `constants` object used in the algorithm configurations below
204
214
  > comes from the `node:zlib` package.
205
215
 
206
- #### Gzip
216
+ **Gzip**
207
217
 
208
218
  Gzip supports two compression engines:
209
219
 
@@ -212,8 +222,8 @@ Gzip supports two compression engines:
212
222
  generally produces smaller gzip files. It depends on the `node-zopfli-es`
213
223
  package.
214
224
 
215
- Without `node-zopfli-es` installed, the following zlib options are used. They
216
- ensure maximum compression with this engine.
225
+ When Zopfli is unavailable or disabled, the following zlib options are used to
226
+ request the highest compression level supported by the zlib engine.
217
227
 
218
228
  ```ts
219
229
  gzip: {
@@ -237,18 +247,18 @@ gzip: {
237
247
  ```
238
248
 
239
249
  > [!TIP] While higher `numiterations` can produce smaller file sizes, it does so
240
- > at the expense of speed. 15 (the normal default) is common, but did not
241
- > meaningfully affect the final compression ratios in testing while taking 3
242
- > times longer. The tests revealed that, for representative minified Astro
243
- > output files, `numiterations: 5` produced files that were identical in size to
244
- > `numiterations: 15`, always smaller than `zlib` while only being slightly
245
- > slower than `zlib`. `blocksplitting` has also been turned off for a similar
246
- > reason. Feel free to experiment if maximum gzip compression is a priority for
247
- > you rather than relying on `brotli`.
248
-
249
- Even with the package installed, Zopfli can be explicitly disabled by providing
250
- custom `zlib` compression options or setting `algorithms.gzip.zopfli` to
251
- `false`.
250
+ > at the expense of speed. In testing representative minified Astro output
251
+ > files, setting it to `5` produced files that were identical in size to `15`
252
+ > (the engine default) while being three times faster. `blocksplitting` has also
253
+ > been turned off for a similar reason. These settings aim to provide meaningful
254
+ > savings over standard gzip while avoiding the extreme processing time
255
+ > associated with higher Zopfli iteration counts. Feel free to experiment if
256
+ > maximum gzip compression is a priority for you rather than relying on
257
+ > `brotli`.
258
+
259
+ Even with the `node-zopfli-es` package installed, Zopfli can be explicitly
260
+ disabled by providing custom `zlib` compression options or setting
261
+ `algorithms.gzip.zopfli` to `false`.
252
262
 
253
263
  ```ts
254
264
  gzip: {
@@ -264,7 +274,7 @@ gzip: {
264
274
  }
265
275
  ```
266
276
 
267
- #### Brotli
277
+ **Brotli**
268
278
 
269
279
  The default Brotli options prioritize compression ratio.
270
280
 
@@ -276,16 +286,16 @@ brotli: {
276
286
  }
277
287
  ```
278
288
 
279
- #### Zstandard
289
+ **Zstandard**
280
290
 
281
291
  Since Brotli generally achieves better compression ratios than Zstandard for web
282
- assets (at the expense of speed) and has been available in browsers for longer,
283
- it is the preferred option for precompression. Zstandard is instead an
284
- attractive middleware option on server rendered pages where compression speed
285
- and resource usage often matter more.
292
+ assets and has been available in browsers for longer, it is the preferred option
293
+ for precompression. Zstandard is instead an attractive middleware option on
294
+ server rendered pages where compression speed and resource usage often matter
295
+ more.
286
296
 
287
- This integration is exclusively for precompressing static assets. Zstandard is
288
- therefore disabled by default. It can, however, be enabled by setting its
297
+ Since this integration is exclusively for precompressing static assets,
298
+ Zstandard is disabled by default. It can, however, be enabled by setting its
289
299
  property to true or providing a configuration object. The default settings for
290
300
  `zstd` are below, prioritizing high compression ratios without overly taxing
291
301
  your system.
@@ -299,19 +309,43 @@ zstd: {
299
309
  ```
300
310
 
301
311
  > [!CAUTION] 19 is the highest standard compression level. Setting this higher
302
- > (20-22) turns on ultra mode which is significantly more compute-intensive. If
312
+ > (20–22) turns on ultra mode which is significantly more compute-intensive. If
303
313
  > you experiment with these higher levels, consider reducing the
304
314
  > `performance.concurrency` option to a conservative value, such as 1, and
305
- > monitor memory usage. A machine with sufficient CPU and memory resources, such
306
- > as a server environment, is recommended.
315
+ > monitor memory usage. A machine or build environment with sufficient CPU and
316
+ > memory resources, such as a cloud build server, is recommended.
317
+
318
+ Native Zstandard compression was added in `node` v22.15.0. In projects still
319
+ using Astro 5 with an older `node` version, Zstandard output can still be
320
+ created by installing the `zstd-napi` package which `astro-precompressor` will
321
+ then automatically use as a fallback.
322
+
323
+ ### Cache
324
+
325
+ The `cache` group controls how the cache should be managed when incremental
326
+ compression is enabled. Its default options are shown below.
327
+
328
+ ```ts
329
+ cache: {
330
+ prune: true,
331
+ }
332
+ ```
333
+
334
+ | Option | Description |
335
+ | ------- | ------------------------------------------------------ |
336
+ | `prune` | Remove obsolete cached artifacts and manifest entries. |
337
+
338
+ > [!NOTE] Prior to v1.2.0, the `prune` option was controlled by setting
339
+ > `pruneCache` under the `filters` property. It has been moved to its own group
340
+ > for clarity.
307
341
 
308
342
  ### File Filtering
309
343
 
310
- The `filters` option controls which build output files should be compressed. Its
344
+ The `filters` group controls which build output files should be compressed. Its
311
345
  default options are shown below.
312
346
 
313
347
  ```ts
314
- WEB_FILE_TYPES = [
348
+ export const WEB_FILE_TYPES = [
315
349
  '.html',
316
350
  '.htm',
317
351
  '.css',
@@ -320,19 +354,20 @@ WEB_FILE_TYPES = [
320
354
  '.cjs',
321
355
  ]
322
356
 
323
- DATA_FILE_TYPES = [
357
+ export const DATA_FILE_TYPES = [
324
358
  '.json',
325
359
  '.xml',
326
360
  '.rss',
327
361
  '.atom',
328
362
  ]
329
363
 
330
- FONT_FILE_TYPES = [
364
+ export const FONT_FILE_TYPES = [
331
365
  '.ttf',
332
366
  '.otf',
333
367
  '.eot',
334
368
  ]
335
369
 
370
+ // ...
336
371
  filters: {
337
372
  minSize: 150,
338
373
  fileTypes: [
@@ -344,17 +379,16 @@ filters: {
344
379
  ],
345
380
  include: undefined,
346
381
  exclude: undefined,
347
- pruneCache: true,
348
382
  }
383
+ // ...
349
384
  ```
350
385
 
351
- | Option | Description |
352
- | ------------ | --------------------------------------------------------- |
353
- | `minSize` | Minimum source file size in bytes. |
354
- | `fileTypes` | File extensions eligible for compression. |
355
- | `include` | Glob patterns specifying files to include. |
356
- | `exclude` | Glob patterns specifying files or directories to exclude. |
357
- | `pruneCache` | Remove obsolete cached artifacts and manifest entries. |
386
+ | Option | Description |
387
+ | ----------- | --------------------------------------------------------- |
388
+ | `minSize` | Minimum source file size in bytes. |
389
+ | `fileTypes` | File extensions eligible for compression. |
390
+ | `include` | Glob patterns specifying files to include. |
391
+ | `exclude` | Glob patterns specifying files or directories to exclude. |
358
392
 
359
393
  If `fileTypes` is specified, the default types are replaced completely. For
360
394
  easier configuration, the `WEB_FILE_TYPES`, `DATA_FILE_TYPES` and
@@ -377,28 +411,126 @@ export default defineConfig({
377
411
  })
378
412
  ```
379
413
 
414
+ Files are evaluated against the global filters first:
415
+
416
+ 1. Files with extensions not listed in `fileTypes` are skipped.
417
+ 2. Files smaller than `minSize` are skipped.
418
+ 3. Files matching any string exclude pattern are skipped.
419
+ 4. If include patterns are configured, files that don't match any include
420
+ pattern are skipped.
421
+
422
+ For files that pass these checks, matching include and exclude objects determine
423
+ which globally enabled compression algorithms are used.
424
+
425
+ **Pattern Matching**
426
+
380
427
  Include and exclude patterns use
381
428
  [picomatch](https://github.com/micromatch/picomatch).
382
429
 
383
430
  Patterns are matched against paths relative to the output directory and use
384
431
  forward slashes.
385
432
 
386
- For example:
433
+ Each entry can be either a string representing a glob pattern or an object
434
+ specifying the algorithms to which a pattern applies.
387
435
 
388
436
  ```ts
389
- exclude: ['drafts/**', '**/ignored/**']
437
+ filters: {
438
+ include: [
439
+ '**/*.html',
440
+ { pattern: '**/*.css', algorithms: ['gzip'] },
441
+ { pattern: '**/*.svg', algorithms: ['brotli'] },
442
+ ],
443
+ exclude: [
444
+ '**/admin/**',
445
+ { pattern: '**/*.css', algorithms: ['gzip', 'zstd'] },
446
+ ],
447
+ }
390
448
  ```
391
449
 
392
- The first pattern excludes files beneath the root-level `drafts` directory. The
393
- second excludes any directory named `ignored`.
450
+ A string pattern applies to all globally enabled algorithms. An object pattern
451
+ applies only to the algorithms listed in its `algorithms` array.
452
+
453
+ > [!IMPORTANT] The top-level `algorithms` and `filters.fileTypes` options are
454
+ > authoritative. Glob filters can restrict which globally enabled algorithms are
455
+ > used for a file, but cannot enable an algorithm that is globally disabled.
456
+ > Likewise, include patterns cannot make a filetype eligible if it is excluded
457
+ > by `filters.fileTypes`.
458
+
459
+ **Include Rules**
460
+
461
+ - If no include patterns are configured, all files that pass the other filters
462
+ are eligible for every globally enabled algorithm.
463
+ - If include patterns are configured, a file must match at least one include
464
+ pattern.
465
+ - A string include pattern makes the file eligible for every globally enabled
466
+ algorithm.
467
+ - An object include pattern makes the file eligible for the algorithms listed in
468
+ its `algorithms` array.
469
+ - If multiple include patterns match, their algorithm selections are combined.
470
+ If any matching pattern is a string, all globally enabled algorithms are
471
+ eligible before exclusions are applied.
472
+
473
+ **Exclude Rules**
474
+
475
+ - A file matching any string exclude pattern is excluded entirely.
476
+ - An object exclude pattern removes only the algorithms listed in its
477
+ `algorithms` array.
478
+ - Multiple exclude patterns are applied independently. If any matching rule
479
+ excludes an algorithm, that algorithm is not used.
480
+ - Exclusions take precedence over inclusions.
481
+
482
+ **Combining Pattern Rules**
483
+
484
+ The following table illustrates how matching include and exclude rules are
485
+ combined. It assumes all three algorithms are globally enabled and the file
486
+ passes the `fileTypes` and `minSize` filters.
487
+
488
+ | Matching include rules | Matching exclude rules | Result |
489
+ | ------------------------------------------- | -------------------------- | ----------------------- |
490
+ | No include patterns configured | None | Gzip, Brotli, Zstandard |
491
+ | String pattern | None | Gzip, Brotli, Zstandard |
492
+ | Object specifying ['gzip'] | None | Gzip |
493
+ | Objects specifying ['gzip'] and ['brotli'] | None | Gzip, Brotli |
494
+ | String pattern | Object specifying ['gzip'] | Brotli, Zstandard |
495
+ | Object specifying ['gzip', 'brotli'] | Object specifying ['gzip'] | Brotli |
496
+ | Any matching include pattern | String pattern | File excluded |
497
+ | Include patterns configured, but none match | None | File skipped |
498
+
499
+ > [!NOTE] The resulting algorithms are always limited to those enabled in the
500
+ > top-level `algorithms` configuration. If no algorithms remain after applying
501
+ > the matching rules, the file is skipped.
502
+
503
+ **Empty Algorithm Lists**
504
+
505
+ An object pattern must specify at least one algorithm. If its list is empty and
506
+ `failOnError` is false, the rule is ignored with a warning. When `failOnError`
507
+ is true, the configuration will fail. Invalid glob patterns and unknown
508
+ algorithm names will always fail.
509
+
510
+ **Example**
394
511
 
395
- Files are matched in the following order:
512
+ ```ts
513
+ filters: {
514
+ fileTypes: ['.html', '.css', '.svg'],
515
+ include: [
516
+ '**/*.{html|svg}',
517
+ { pattern: '**/*.css', algorithms: ['gzip'] },
518
+ ],
519
+ exclude: [
520
+ '**/drafts/**',
521
+ { pattern: '**/*.svg', algorithms: ['gzip'] },
522
+ ],
523
+ }
524
+ ```
396
525
 
397
- 1. If include patterns are configured, files that don't match any of them are
398
- skipped.
399
- 2. Files matching an exclude pattern are skipped.
400
- 3. Files with extensions not listed in fileTypes are skipped.
401
- 4. Files smaller than minSize are skipped.
526
+ In this example, HTML files receive every globally enabled algorithm, CSS files
527
+ receive Gzip only, and SVG files receive every globally enabled algorithm except
528
+ Gzip. Files beneath `drafts/` are excluded entirely.
529
+
530
+ > [!TIP] Because files only need to match one include pattern, adding `**` or
531
+ > `'**/**'` (which match all file paths) to the include list causes all
532
+ > otherwise eligible files pass the include filter, regardless of any other
533
+ > include patterns specified.
402
534
 
403
535
  ### Performance
404
536
 
@@ -422,8 +554,9 @@ performance: {
422
554
  | `discardCompressionIfLarger` | Whether to discard compressed output when the original is smaller. |
423
555
 
424
556
  The default value for `concurrency` is set automatically based on the number of
425
- logical processors that Node.js reports as available. This is usually optimal,
426
- but lower values may use less memory at the expense of speed.
557
+ logical processors that Node.js reports as available. This provides a sensible
558
+ default, but lower values may use less memory at the expense of speed. Feel free
559
+ to experiment if you feel the build is stuttering during compression.
427
560
 
428
561
  When `incremental` is enabled, compression artifacts are retained in the cache
429
562
  along with a hash of the source file. While this may marginally slow down
@@ -442,14 +575,20 @@ copied into the build output.
442
575
  The integration maintains a cache inside Astro's configured cache directory.
443
576
 
444
577
  Cached compression artifacts are associated with their source files using
445
- content hashes. When a source file hasn't changed, its cached artifacts can be
446
- reused instead of running the compression engine again.
578
+ content hashes, so changes to file contents trigger recompression while
579
+ unchanged files can reuse cached results.
447
580
 
448
581
  The cache is maintained independently of the build output, allowing compressed
449
582
  sidecars to be restored along with their modification timestamps.
450
583
 
451
- When `filters.pruneCache` is enabled, obsolete artifacts associated with files
452
- that no longer exist in the output directory are removed.
584
+ When `cache.prune` is enabled, obsolete cached compression artifacts and
585
+ manifest entries are removed. This keeps the incremental cache from retaining
586
+ entries that are no longer relevant to the current build.
587
+
588
+ Output sidecars are handled separately from cache pruning. If Vite's
589
+ `build.emptyOutDir` option is manually set to `false`, output sidecars will be
590
+ removed if their source files have changed. Otherwise, they will automatically
591
+ be cleaned up by Vite prior to every build.
453
592
 
454
593
  ## Output
455
594
 
@@ -466,7 +605,7 @@ dist/
466
605
  │ └─ styles.css
467
606
  ```
468
607
 
469
- The resulting output may look like:
608
+ The resulting output will look like:
470
609
 
471
610
  ```text
472
611
  dist/
@@ -489,21 +628,22 @@ The original files are never modified or replaced.
489
628
  Three levels of logging detail are available:
490
629
 
491
630
  1. **Summary (`logLevel: 0`):** A concise build summary along with any errors.
492
- 2. **Detailed (`logLevel: 1`):** Per-file processing information, cache status,
631
+ 2. **Breakdown (`logLevel: 1`):** Per-file processing information, cache status,
493
632
  compression statistics, and a more detailed summary.
494
- 3. **Debug (`logLevel: 2`):** Additional diagnostic messages explaining the
495
- individual processing steps.
496
-
497
- Even when `logLevel` is set to `2`, debug messages will only be shown when the
498
- `--verbose` flag is added to the `astro build` command. The default level is `2`
499
- to match Astro's own logging conventions.
500
-
501
- > [!TIP] Set this value to 0 if you prefer concise logs.
633
+ 3. **Diagnostics (`logLevel: 2`):** Additional diagnostic messages explaining
634
+ the individual processing steps.
502
635
 
503
636
  ```ts
504
- logLevel: 0
637
+ logLevel: 2
505
638
  ```
506
639
 
640
+ When `logLevel` is set to `2`, debug messages will only be shown when the
641
+ `--verbose` flag is added to the `astro build` command; otherwise it produces
642
+ the same output as `logLevel: 1`. The default level is `2` to match Astro's own
643
+ logging conventions.
644
+
645
+ > [!TIP] Set this value to 0 if you prefer concise logs.
646
+
507
647
  ## Build Lifecycle
508
648
 
509
649
  The integration uses Astro's build lifecycle hooks:
@@ -528,9 +668,9 @@ The integration uses Astro's build lifecycle hooks:
528
668
  ### Apache
529
669
 
530
670
  Apache's `rewrite_module` (`mod_rewrite.c`) can be used to redirect browsers to
531
- the sidecars. Here is a sample `.htaccess` configuration that will work for most
532
- sites with the default options enabled. It does not include a section for
533
- Zstandard, since that algorithm is disabled by default.
671
+ the sidecars by rewriting requests. Here is a sample `.htaccess` configuration
672
+ that will work for most sites with the default options enabled. It does not
673
+ include a section for Zstandard, since that algorithm is disabled by default.
534
674
 
535
675
  ```apacheconf
536
676
  # SERVE COMPRESSED FILES
@@ -575,14 +715,15 @@ RewriteRule \.eot\.(br|gz)$ - [T=application/vnd.ms-fontobject,E=no-brotli:1,E=n
575
715
  </FilesMatch>
576
716
  ```
577
717
 
578
- > [!TIP] Adjust the file types above to match your `astro-precompressor`
718
+ > [!TIP] Adjust the filetypes above to match your `astro-precompressor`
579
719
  > configuration.
580
720
 
581
721
  > [!WARNING] The `.htaccess` configuration above is representative and does not
582
722
  > guard against a missing `mod_rewrite`. It assumes `mod_headers` and `mod_mime`
583
723
  > are available. The encoding conditions reject explicitly disabled encodings
584
724
  > (q=0), but do not implement complete quality-value negotiation or wildcard
585
- > handling. Always test before using it in a production environment.
725
+ > handling. Always test with your actual Apache setup and file types before
726
+ > using it in a production environment.
586
727
 
587
728
  ### Nginx
588
729
 
@@ -0,0 +1,11 @@
1
+ import { constants } from 'node:zlib';
2
+ import type { BrotliOptions } from 'node:zlib';
3
+ import type { AlgorithmOptions, ResolvedAlgorithmOptions, CompressorFactory } from './types.js';
4
+ export declare const DEFAULT_BROTLI_OPTIONS: {
5
+ readonly params: {
6
+ readonly [constants.BROTLI_PARAM_QUALITY]: number;
7
+ };
8
+ };
9
+ export declare function resolveBrotliOptions(value: AlgorithmOptions['brotli']): ResolvedAlgorithmOptions['brotli'];
10
+ export declare function createBrotliCompressorFactory(options?: BrotliOptions): CompressorFactory;
11
+ //# sourceMappingURL=brotli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"brotli.d.ts","sourceRoot":"","sources":["../src/brotli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,SAAS,EAAE,MAAM,WAAW,CAAA;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAE9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAE/F,eAAO,MAAM,sBAAsB;;QAEjC,SAAA,CAAC,SAAS,CAAC,oBAAoB,CAAC,SAA8B;;CAE9B,CAAA;AAElC,wBAAgB,oBAAoB,CACnC,KAAK,EAAE,gBAAgB,CAAC,QAAQ,CAAC,GAC/B,wBAAwB,CAAC,QAAQ,CAAC,CAapC;AAED,wBAAgB,6BAA6B,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,iBAAiB,CAExF"}
package/dist/brotli.js ADDED
@@ -0,0 +1,23 @@
1
+ import { createBrotliCompress, constants } from 'node:zlib';
2
+ export const DEFAULT_BROTLI_OPTIONS = {
3
+ params: {
4
+ [constants.BROTLI_PARAM_QUALITY]: constants.BROTLI_MAX_QUALITY,
5
+ },
6
+ };
7
+ export function resolveBrotliOptions(value) {
8
+ if (!value) {
9
+ return false;
10
+ }
11
+ return {
12
+ ...DEFAULT_BROTLI_OPTIONS,
13
+ ...(typeof value === 'object' ? value : {}),
14
+ params: {
15
+ ...DEFAULT_BROTLI_OPTIONS.params,
16
+ ...(typeof value === 'object' ? value.params : {}),
17
+ },
18
+ };
19
+ }
20
+ export function createBrotliCompressorFactory(options) {
21
+ return () => createBrotliCompress(options);
22
+ }
23
+ //# sourceMappingURL=brotli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"brotli.js","sourceRoot":"","sources":["../src/brotli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAK3D,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACrC,MAAM,EAAE;QACP,CAAC,SAAS,CAAC,oBAAoB,CAAC,EAAE,SAAS,CAAC,kBAAkB;KAC9D;CACgC,CAAA;AAElC,MAAM,UAAU,oBAAoB,CACnC,KAAiC;IAEjC,IAAI,CAAC,KAAK,EAAE,CAAC;QACZ,OAAO,KAAK,CAAA;IACb,CAAC;IAED,OAAO;QACN,GAAG,sBAAsB;QACzB,GAAG,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3C,MAAM,EAAE;YACP,GAAG,sBAAsB,CAAC,MAAM;YAChC,GAAG,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;SAClD;KACD,CAAA;AACF,CAAC;AAED,MAAM,UAAU,6BAA6B,CAAC,OAAuB;IACpE,OAAO,GAAG,EAAE,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAA;AAC3C,CAAC"}
package/dist/build.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import type { Logger, ResolvedOptions, ZopfliModule } from './types.js';
2
- export declare function runBuild(outputDirectory: string, cacheDirectory: string, configHash: string, options: ResolvedOptions, logger: Logger, zopfli: ZopfliModule | undefined): Promise<void>;
1
+ import type { Compressors, Logger, ResolvedOptions } from './types.js';
2
+ export declare function runBuild(outputDirectory: string, cacheDirectory: string, configHash: string, options: ResolvedOptions, logger: Logger, compressors: Compressors): Promise<void>;
3
3
  //# sourceMappingURL=build.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAiCA,OAAO,KAAK,EAIX,MAAM,EACN,eAAe,EACf,YAAY,EACZ,MAAM,YAAY,CAAA;AAgKnB,wBAAsB,QAAQ,CAC7B,eAAe,EAAE,MAAM,EACvB,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,eAAe,EACxB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,YAAY,GAAG,SAAS,GAC9B,OAAO,CAAC,IAAI,CAAC,CAkQf"}
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAyCA,OAAO,KAAK,EAGX,WAAW,EAEX,MAAM,EAEN,eAAe,EACf,MAAM,YAAY,CAAA;AAoPnB,wBAAsB,QAAQ,CAC7B,eAAe,EAAE,MAAM,EACvB,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,eAAe,EACxB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,WAAW,GACtB,OAAO,CAAC,IAAI,CAAC,CA4Rf"}