@divriots/jampack 0.11.2 → 0.11.3

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
@@ -35,16 +35,78 @@ Optimizes static websites for best user experience and best Core Web Vitals scor
35
35
 
36
36
  `jampack` is a post-processing tool that takes the output of your [Static Site Generator (aka SSG)](https://jamstack.org/generators/) and optimizes it for best user experience and best [Core Web Vitals](https://web.dev/learn-core-web-vitals/) scores.
37
37
 
38
- [Read the introduction blog post](https://divriots.com/blog/introducing-jampack)
38
+ [Read the introduction blog post](https://divriots.com/blog/introducing-jampack/)
39
39
 
40
40
  ## What can `jampack` do?
41
41
 
42
- - [Optimize images](https://jampack.divriots.com/features/optimize-images)
43
- - [Optimize assets above-the-fold](https://jampack.divriots.com/features/optimize-above-the-fold)
44
- - [Embed small images](https://jampack.divriots.com/features/embed-small-images)
45
- - [Compress all assets](https://jampack.divriots.com/features/compress-all)
46
- - [Fix things automatically](https://jampack.divriots.com/features/autofixes)
47
- - [Raise warnings](https://jampack.divriots.com/features/warnings)
42
+ ### `<img>`
43
+
44
+ ```html
45
+ <img src="./redpanda.jpg" alt="Red panda">
46
+ ```
47
+
48
+ becomes responsive with dimensions:
49
+
50
+ ```html
51
+ <img src="./redpanda.jpg.webp" alt="Red panda"
52
+ srcset="./redpanda.jpg.webp 3872w, ./redpanda@3572w.jpg.webp 3572w, ./redpanda@3272w.jpg.webp 3272w, ./redpanda@2972w.jpg.webp 2972w, ./redpanda@2672w.jpg.webp 2672w, ./redpanda@2372w.jpg.webp 2372w, ./redpanda@2072w.jpg.webp 2072w, ./redpanda@1772w.jpg.webp 1772w, ./redpanda@1472w.jpg.webp 1472w, ./redpanda@1172w.jpg.webp 1172w, ./redpanda@872w.jpg.webp 872w"
53
+ sizes="100vw"
54
+ loading="lazy"
55
+ decoding="async"
56
+ width="3872"
57
+ height="2592">
58
+ ```
59
+
60
+ ### `<picture>`
61
+
62
+ ```html
63
+ <picture>
64
+ <img src="./redpanda.jpg" alt="Red panda">
65
+ </picture>
66
+ ```
67
+
68
+ becomes responsive with multiple formats including AVIF:
69
+
70
+ ```html
71
+ <picture>
72
+ <source type="image/avif" srcset="./redpanda@1936w.avif 1936w, ./redpanda@1636w.avif 1636w, ./redpanda@1336w.avif 1336w, ./redpanda@1036w.avif 1036w, ./redpanda@736w.avif 736w">
73
+ <source type="image/webp" srcset="./redpanda@1936w.webp 1936w, ./redpanda@1636w.webp 1636w, ./redpanda@1336w.webp 1336w, ./redpanda@1036w.webp 1036w, ./redpanda@736w.webp 736w">
74
+ <img src="./redpanda.jpg" alt="Red panda" loading="lazy" decoding="async" width="1936" height="1296" srcset="./redpanda.jpg 1936w, ./redpanda@1636w.jpg 1636w, ./redpanda@1336w.jpg 1336w, ./redpanda@1036w.jpg 1036w, ./redpanda@736w.jpg 736w" sizes="100vw">
75
+ </picture>
76
+ ```
77
+
78
+ ### Above & below-the-fold
79
+
80
+ `jampack` optimizes assets above-the-fold ⬆️.
81
+
82
+ - Images are loaded with higher priority.
83
+ - Images are compress as Progressive JPEG.
84
+ - Small images are embedded in HTML.
85
+
86
+ Lazy-load assets below-the-fold ⬇️.
87
+
88
+ - Images and Iframes are lazy loaded.
89
+
90
+ See [details](https://jampack.divriots.com/features/optimize-above-the-fold/).
91
+
92
+ ### All assets are compressed
93
+
94
+ In a 2nd PASS, `jampack` compresses all untouched assets and keep the same name and the same format.
95
+
96
+ | Extension | Compressor |
97
+ | --------------- | --------------------- |
98
+ | `.html`,`.htm` | [`html-minifier-terser`](https://github.com/terser/html-minifier-terser) |
99
+ | `.css` | Best of [`csso`](https://github.com/css/csso) & [`lightningCSS`](https://lightningcss.dev) |
100
+ | `.js` | [`swc`](https://swc.rs/) |
101
+ | `.svg` | [`svgo`](https://github.com/svg/svgo) |
102
+ | `.jpg`,`.jpeg` | [`sharp`](https://sharp.pixelplumbing.com/) |
103
+ | `.png` | [`sharp`](https://sharp.pixelplumbing.com/) |
104
+ | `.webp` | [`sharp`](https://sharp.pixelplumbing.com/) |
105
+ | `.avif` | [`sharp`](https://sharp.pixelplumbing.com/) |
106
+
107
+ ### And more!
108
+
109
+ See [Documentation](https://jampack.divriots.com/) for all feature list and examples.
48
110
 
49
111
  ## Quick use
50
112
 
@@ -53,7 +115,7 @@ Optimizes static websites for best user experience and best Core Web Vitals scor
53
115
  npx @divriots/jampack ./dist
54
116
  ```
55
117
 
56
- For more options see [CLI options](https://jampack.divriots.com/cli-options).
118
+ For more options see [CLI options](https://jampack.divriots.com/cli-options/).
57
119
 
58
120
  ## `jampack` used in the wild
59
121
 
@@ -8,9 +8,12 @@ async function minifyJSinHTML(originalCode) {
8
8
  return originalCode;
9
9
  }
10
10
  async function minifyCSSinHTML(originalCode, type) {
11
+ // Don't compress media
12
+ if (type === 'media')
13
+ return originalCode;
11
14
  const originalBuffer = Buffer.from(originalCode);
12
15
  const newCSS = await compressCSS(originalBuffer, type);
13
- if (newCSS && newCSS.length < originalBuffer.length)
16
+ if (newCSS && newCSS.length > 0 && newCSS.length < originalBuffer.length)
14
17
  return newCSS.toString();
15
18
  return originalCode;
16
19
  }
@@ -5,6 +5,11 @@ const default_options = {
5
5
  image: {
6
6
  embed_size: 1500,
7
7
  srcset_min_width: 640,
8
+ external: {
9
+ process: 'download',
10
+ src_include: /.*/,
11
+ src_exclude: null,
12
+ },
8
13
  compress: true,
9
14
  jpeg: {
10
15
  options: {
@@ -10,6 +10,11 @@ export type Options = {
10
10
  image: {
11
11
  embed_size: number;
12
12
  srcset_min_width: number;
13
+ external: {
14
+ process: 'download' | 'add-dimensions-only' | 'off';
15
+ src_include: RegExp | undefined;
16
+ src_exclude: RegExp | null;
17
+ };
13
18
  compress: boolean;
14
19
  jpeg: {
15
20
  options: {
package/dist/optimize.js CHANGED
@@ -184,9 +184,21 @@ async function processImage(htmlfile, $, imgElement, isAboveTheFold) {
184
184
  * Attribute 'decoding'
185
185
  */
186
186
  img.attr('decoding', 'async');
187
+ /*
188
+ * Check for external images
189
+ */
187
190
  if (!isLocal(attrib_src)) {
188
- // Image not local, don't touch it
189
- return;
191
+ switch (config.image.external.process) {
192
+ case 'off':
193
+ // Don't process external images
194
+ return;
195
+ case 'download':
196
+ // Download external image for local processing
197
+ break;
198
+ case 'add-dimensions-only':
199
+ // Only add dimensions of image
200
+ return;
201
+ }
190
202
  }
191
203
  /*
192
204
  * Loading image
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@divriots/jampack",
3
- "version": "0.11.2",
3
+ "version": "0.11.3",
4
4
  "description": "Packer for static websites",
5
5
  "author": "Georges Gomes @georges-gomes",
6
6
  "bin": {