@divriots/jampack 0.11.2 → 0.11.4
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 +70 -8
- package/dist/compressors/css.js +3 -18
- package/dist/compressors/html.js +4 -1
- package/dist/config-default.js +5 -0
- package/dist/config-types.d.ts +5 -0
- package/dist/optimize.js +14 -2
- package/package.json +1 -3
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
|
package/dist/compressors/css.js
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
import { minify as csso } from 'csso';
|
|
2
1
|
import { transform as lightcss, transformStyleAttribute as lightcssStyleAttribute, } from 'lightningcss';
|
|
3
2
|
export async function compressCSS(originalCode, type) {
|
|
4
|
-
// csso only support css files. No inline style
|
|
5
|
-
let cssoCSSData = undefined;
|
|
6
|
-
if (type !== 'inline') {
|
|
7
|
-
// Compress with csso
|
|
8
|
-
cssoCSSData = Buffer.from(await csso(originalCode.toString(), { comments: false }).css);
|
|
9
|
-
}
|
|
10
3
|
// Compress with lightningcss
|
|
11
|
-
let lightCSSData;
|
|
4
|
+
let lightCSSData = undefined;
|
|
12
5
|
try {
|
|
13
6
|
const options = {
|
|
14
7
|
code: originalCode,
|
|
@@ -24,18 +17,10 @@ export async function compressCSS(originalCode, type) {
|
|
|
24
17
|
}
|
|
25
18
|
catch (e) {
|
|
26
19
|
// Error while processing with lightningcss
|
|
27
|
-
//
|
|
20
|
+
// Take original code
|
|
28
21
|
}
|
|
29
22
|
let resultBuffer = undefined;
|
|
30
|
-
|
|
31
|
-
if (cssoCSSData && lightCSSData) {
|
|
32
|
-
resultBuffer =
|
|
33
|
-
cssoCSSData.length <= lightCSSData.length ? cssoCSSData : lightCSSData;
|
|
34
|
-
}
|
|
35
|
-
else if (cssoCSSData && !lightCSSData) {
|
|
36
|
-
resultBuffer = cssoCSSData;
|
|
37
|
-
}
|
|
38
|
-
else if (!cssoCSSData && lightCSSData) {
|
|
23
|
+
if (lightCSSData && lightCSSData.length < originalCode.length) {
|
|
39
24
|
resultBuffer = lightCSSData;
|
|
40
25
|
}
|
|
41
26
|
return resultBuffer || originalCode;
|
package/dist/compressors/html.js
CHANGED
|
@@ -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
|
}
|
package/dist/config-default.js
CHANGED
package/dist/config-types.d.ts
CHANGED
|
@@ -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
|
-
|
|
189
|
-
|
|
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.
|
|
3
|
+
"version": "0.11.4",
|
|
4
4
|
"description": "Packer for static websites",
|
|
5
5
|
"author": "Georges Gomes @georges-gomes",
|
|
6
6
|
"bin": {
|
|
@@ -19,12 +19,10 @@
|
|
|
19
19
|
"@divriots/cheerio": "1.0.0-rc.12",
|
|
20
20
|
"@proload/core": "^0.3.3",
|
|
21
21
|
"@swc/core": "^1.3.57",
|
|
22
|
-
"@types/csso": "^5.0.0",
|
|
23
22
|
"@types/html-minifier-terser": "^7.0.0",
|
|
24
23
|
"@types/sharp": "^0.32.0",
|
|
25
24
|
"@types/svgo": "^3.0.0",
|
|
26
25
|
"commander": "^10.0.1",
|
|
27
|
-
"csso": "^5.0.5",
|
|
28
26
|
"deepmerge": "^4.3.1",
|
|
29
27
|
"file-type": "^18.4.0",
|
|
30
28
|
"globby": "^13.1.4",
|