@divriots/jampack 0.24.2 → 0.24.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/LICENSE +0 -0
- package/README.md +0 -0
- package/dist/config-default.js +3 -1
- package/dist/config-types.d.ts +3 -1
- package/dist/index.js +1 -1
- package/dist/optimize.js +47 -40
- package/dist/utils/resource.js +0 -2
- package/package.json +9 -8
package/LICENSE
CHANGED
|
File without changes
|
package/README.md
CHANGED
|
File without changes
|
package/dist/config-default.js
CHANGED
|
@@ -17,6 +17,8 @@ const default_options = {
|
|
|
17
17
|
srcset_min_width: 390 * 2, // HiDPI phone
|
|
18
18
|
srcset_max_width: 1920 * 2, // 4K
|
|
19
19
|
max_width: 99999,
|
|
20
|
+
src_include: /^.*$/,
|
|
21
|
+
src_exclude: /^\/vercel\/image\?/, // Ignore /vervel/image? URLs because not local and most likely already optimized,
|
|
20
22
|
external: {
|
|
21
23
|
process: 'off',
|
|
22
24
|
src_include: /^.*$/,
|
|
@@ -24,7 +26,7 @@ const default_options = {
|
|
|
24
26
|
},
|
|
25
27
|
cdn: {
|
|
26
28
|
process: 'off',
|
|
27
|
-
src_include:
|
|
29
|
+
src_include: null,
|
|
28
30
|
src_exclude: null,
|
|
29
31
|
},
|
|
30
32
|
compress: true,
|
package/dist/config-types.d.ts
CHANGED
|
@@ -24,6 +24,8 @@ export type Options = {
|
|
|
24
24
|
srcset_min_width: number;
|
|
25
25
|
srcset_max_width: number;
|
|
26
26
|
max_width: number;
|
|
27
|
+
src_include: RegExp;
|
|
28
|
+
src_exclude: RegExp | null;
|
|
27
29
|
external: {
|
|
28
30
|
process: 'off' | 'download';
|
|
29
31
|
src_include: RegExp;
|
|
@@ -31,7 +33,7 @@ export type Options = {
|
|
|
31
33
|
};
|
|
32
34
|
cdn: {
|
|
33
35
|
process: 'off' | 'optimize';
|
|
34
|
-
src_include: RegExp;
|
|
36
|
+
src_include: RegExp | null;
|
|
35
37
|
src_exclude: RegExp | null;
|
|
36
38
|
transformer?: UrlTransformer;
|
|
37
39
|
};
|
package/dist/index.js
CHANGED
|
@@ -65,7 +65,7 @@ program
|
|
|
65
65
|
mkdirSync(join(dir, '_jampack'));
|
|
66
66
|
}
|
|
67
67
|
catch (e) {
|
|
68
|
-
console.error('
|
|
68
|
+
console.error('Folder `_jampack` is present in target folder. This means that jampack has already processed this folder. You should always run jampack on clean build of the static website.');
|
|
69
69
|
exit(1);
|
|
70
70
|
}
|
|
71
71
|
// Inject config into modules
|
package/dist/optimize.js
CHANGED
|
@@ -220,6 +220,10 @@ async function processImage(htmlfile, img, isAboveTheFold) {
|
|
|
220
220
|
});
|
|
221
221
|
return;
|
|
222
222
|
}
|
|
223
|
+
if (!isIncluded(attrib_src, config.image.src_include, config.image.src_exclude)) {
|
|
224
|
+
// Setup to ignore
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
223
227
|
/*
|
|
224
228
|
* Attribute 'alt'
|
|
225
229
|
*/
|
|
@@ -270,48 +274,51 @@ async function processImage(htmlfile, img, isAboveTheFold) {
|
|
|
270
274
|
/*
|
|
271
275
|
* Check for external images
|
|
272
276
|
*/
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
}
|
|
285
|
-
if (!cdnTransformer)
|
|
286
|
-
break;
|
|
287
|
-
if (!isIncluded(attrib_src, config.image.cdn.src_include, config.image.cdn.src_exclude))
|
|
277
|
+
switch (config.image.cdn.process) {
|
|
278
|
+
case 'off':
|
|
279
|
+
break;
|
|
280
|
+
case 'optimize':
|
|
281
|
+
let cdnTransformer = config.image.cdn.transformer;
|
|
282
|
+
if (cdnTransformer && !config.image.cdn.src_include) {
|
|
283
|
+
throw new Error('config.image.cdn.src_include is required when specifying a config.image.cdn.transformer');
|
|
284
|
+
}
|
|
285
|
+
if (!cdnTransformer) {
|
|
286
|
+
const canonical = getCanonicalCdnForUrl(attrib_src);
|
|
287
|
+
if (!canonical)
|
|
288
288
|
break;
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
$
|
|
300
|
-
|
|
301
|
-
msg: `Missing or malformed 'height' attribute for image ${attrib_src}, unable to perform CDN transform`,
|
|
302
|
-
});
|
|
303
|
-
return;
|
|
304
|
-
}
|
|
305
|
-
const new_srcset = await generateSrcSetForCdn(attrib_src, cdnTransformer, attrib_width, attrib_height);
|
|
306
|
-
if (new_srcset !== null) {
|
|
307
|
-
img.attr('srcset', new_srcset);
|
|
308
|
-
}
|
|
309
|
-
// Add sizes attribute if not specified
|
|
310
|
-
if (img.attr('srcset') && !img.attr('sizes')) {
|
|
311
|
-
img.attr('sizes', '100vw');
|
|
312
|
-
}
|
|
289
|
+
cdnTransformer = getTransformer(canonical.cdn);
|
|
290
|
+
}
|
|
291
|
+
if (!cdnTransformer)
|
|
292
|
+
break;
|
|
293
|
+
if (!isIncluded(attrib_src, config.image.cdn.src_include || /.*/, config.image.cdn.src_exclude))
|
|
294
|
+
break;
|
|
295
|
+
let attrib_width = getIntAttr(img, 'width');
|
|
296
|
+
if (!attrib_width) {
|
|
297
|
+
$state.reportIssue(htmlfile, {
|
|
298
|
+
type: 'warn',
|
|
299
|
+
msg: `Missing or malformed'width' attribute for image ${attrib_src}, unable to perform CDN transform`,
|
|
300
|
+
});
|
|
313
301
|
return;
|
|
314
|
-
|
|
302
|
+
}
|
|
303
|
+
let attrib_height = getIntAttr(img, 'height');
|
|
304
|
+
if (!attrib_height) {
|
|
305
|
+
$state.reportIssue(htmlfile, {
|
|
306
|
+
type: 'warn',
|
|
307
|
+
msg: `Missing or malformed 'height' attribute for image ${attrib_src}, unable to perform CDN transform`,
|
|
308
|
+
});
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
const new_srcset = await generateSrcSetForCdn(attrib_src, cdnTransformer, attrib_width, attrib_height);
|
|
312
|
+
if (new_srcset !== null) {
|
|
313
|
+
img.attr('srcset', new_srcset);
|
|
314
|
+
}
|
|
315
|
+
// Add sizes attribute if not specified
|
|
316
|
+
if (img.attr('srcset') && !img.attr('sizes')) {
|
|
317
|
+
img.attr('sizes', '100vw');
|
|
318
|
+
}
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
if (!isLocal(attrib_src)) {
|
|
315
322
|
switch (config.image.external.process) {
|
|
316
323
|
case 'off': // Don't process external images
|
|
317
324
|
return;
|
package/dist/utils/resource.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@divriots/jampack",
|
|
3
|
-
"version": "0.24.
|
|
3
|
+
"version": "0.24.4",
|
|
4
4
|
"cache-version": {
|
|
5
5
|
"img": "v1",
|
|
6
6
|
"img-ext": "v1"
|
|
@@ -58,17 +58,18 @@
|
|
|
58
58
|
"tslib": "^2.6.2",
|
|
59
59
|
"typescript": "^5.4.5"
|
|
60
60
|
},
|
|
61
|
-
"engines": {
|
|
62
|
-
"node": ">=14.0.0"
|
|
63
|
-
},
|
|
64
|
-
"bugs": "https://github.com/divriots/jampack/issues",
|
|
65
|
-
"keywords": [],
|
|
66
|
-
"types": "dist/index.d.ts",
|
|
67
61
|
"scripts": {
|
|
68
62
|
"watch": "pnpm build --watch",
|
|
69
63
|
"try": "shx rm -fr demo && cp -R demo_drc demo && node ./dist/index.js ./demo --nocache",
|
|
70
64
|
"build": "shx rm -rf dist && tsc -b",
|
|
71
65
|
"lint": "eslint . --ext .ts --config .eslintrc",
|
|
66
|
+
"prepublishOnly": "pnpm build",
|
|
72
67
|
"cleanAllDotJampack": "find -s . | grep '.jampack$' | xargs rm -fr"
|
|
73
|
-
}
|
|
68
|
+
},
|
|
69
|
+
"engines": {
|
|
70
|
+
"node": ">=14.0.0"
|
|
71
|
+
},
|
|
72
|
+
"bugs": "https://github.com/divriots/jampack/issues",
|
|
73
|
+
"keywords": [],
|
|
74
|
+
"types": "dist/index.d.ts"
|
|
74
75
|
}
|