@divriots/jampack 0.24.2 → 0.24.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/dist/config-default.js +1 -1
- package/dist/config-types.d.ts +1 -1
- package/dist/optimize.js +43 -40
- package/dist/utils/resource.js +0 -2
- package/package.json +1 -1
package/dist/config-default.js
CHANGED
package/dist/config-types.d.ts
CHANGED
package/dist/optimize.js
CHANGED
|
@@ -270,48 +270,51 @@ async function processImage(htmlfile, img, isAboveTheFold) {
|
|
|
270
270
|
/*
|
|
271
271
|
* Check for external images
|
|
272
272
|
*/
|
|
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))
|
|
273
|
+
switch (config.image.cdn.process) {
|
|
274
|
+
case 'off':
|
|
275
|
+
break;
|
|
276
|
+
case 'optimize':
|
|
277
|
+
let cdnTransformer = config.image.cdn.transformer;
|
|
278
|
+
if (cdnTransformer && !config.image.cdn.src_include) {
|
|
279
|
+
throw new Error('config.image.cdn.src_include is required when specifying a config.image.cdn.transformer');
|
|
280
|
+
}
|
|
281
|
+
if (!cdnTransformer) {
|
|
282
|
+
const canonical = getCanonicalCdnForUrl(attrib_src);
|
|
283
|
+
if (!canonical)
|
|
288
284
|
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
|
-
}
|
|
285
|
+
cdnTransformer = getTransformer(canonical.cdn);
|
|
286
|
+
}
|
|
287
|
+
if (!cdnTransformer)
|
|
288
|
+
break;
|
|
289
|
+
if (!isIncluded(attrib_src, config.image.cdn.src_include || /.*/, config.image.cdn.src_exclude))
|
|
290
|
+
break;
|
|
291
|
+
let attrib_width = getIntAttr(img, 'width');
|
|
292
|
+
if (!attrib_width) {
|
|
293
|
+
$state.reportIssue(htmlfile, {
|
|
294
|
+
type: 'warn',
|
|
295
|
+
msg: `Missing or malformed'width' attribute for image ${attrib_src}, unable to perform CDN transform`,
|
|
296
|
+
});
|
|
313
297
|
return;
|
|
314
|
-
|
|
298
|
+
}
|
|
299
|
+
let attrib_height = getIntAttr(img, 'height');
|
|
300
|
+
if (!attrib_height) {
|
|
301
|
+
$state.reportIssue(htmlfile, {
|
|
302
|
+
type: 'warn',
|
|
303
|
+
msg: `Missing or malformed 'height' attribute for image ${attrib_src}, unable to perform CDN transform`,
|
|
304
|
+
});
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
const new_srcset = await generateSrcSetForCdn(attrib_src, cdnTransformer, attrib_width, attrib_height);
|
|
308
|
+
if (new_srcset !== null) {
|
|
309
|
+
img.attr('srcset', new_srcset);
|
|
310
|
+
}
|
|
311
|
+
// Add sizes attribute if not specified
|
|
312
|
+
if (img.attr('srcset') && !img.attr('sizes')) {
|
|
313
|
+
img.attr('sizes', '100vw');
|
|
314
|
+
}
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
if (!isLocal(attrib_src)) {
|
|
315
318
|
switch (config.image.external.process) {
|
|
316
319
|
case 'off': // Don't process external images
|
|
317
320
|
return;
|
package/dist/utils/resource.js
CHANGED