@stratawp/vite-plugin 0.2.1 → 0.3.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/dist/index.d.ts CHANGED
@@ -291,16 +291,23 @@ interface ImageOptions {
291
291
  */
292
292
  dest?: string;
293
293
  /**
294
- * Emit sibling .webp for jpg/png
294
+ * Emit sibling .webp for jpg/png. Kept for backwards compatibility:
295
+ * `false` removes 'webp' from `formats`.
295
296
  * @default true
296
297
  */
297
298
  webp?: boolean;
299
+ /**
300
+ * Sibling formats emitted next to jpg/png sources.
301
+ * @default ['avif', 'webp']
302
+ */
303
+ formats?: Array<'avif' | 'webp'>;
298
304
  /**
299
305
  * Per-format quality (0-100)
300
306
  */
301
307
  quality?: {
302
308
  jpeg?: number;
303
309
  png?: number;
310
+ avif?: number;
304
311
  webp?: number;
305
312
  };
306
313
  }
package/dist/index.js CHANGED
@@ -623,9 +623,12 @@ function strataWPImages(options = {}) {
623
623
  webp = true,
624
624
  quality = {}
625
625
  } = options;
626
+ const formats = (options.formats ?? ["avif", "webp"]).filter(
627
+ (format) => !(format === "webp" && webp === false)
628
+ );
626
629
  const jpegQuality = quality.jpeg ?? 75;
627
630
  const pngQuality = quality.png ?? 80;
628
- const webpQuality = quality.webp ?? 75;
631
+ const siblingQuality = { avif: quality.avif ?? 50, webp: quality.webp ?? 75 };
629
632
  let root = process.cwd();
630
633
  return {
631
634
  name: "stratawp:images",
@@ -671,12 +674,20 @@ function strataWPImages(options = {}) {
671
674
  await copyFile(srcFile, destFile);
672
675
  }
673
676
  }
674
- if (webp && (ext === ".jpg" || ext === ".jpeg" || ext === ".png")) {
675
- const webpFile = destFile.replace(/\.[^.]+$/i, ".webp");
676
- if (await isNewer(srcFile, webpFile)) {
677
+ if (ext === ".jpg" || ext === ".jpeg" || ext === ".png") {
678
+ for (const format of formats) {
679
+ const siblingFile = destFile.replace(/\.[^.]+$/i, `.${format}`);
680
+ if (!await isNewer(srcFile, siblingFile)) {
681
+ continue;
682
+ }
677
683
  try {
678
- await sharp(srcFile, { sequentialRead: true }).webp({ quality: webpQuality }).toFile(webpFile);
679
- } catch {
684
+ const pipeline = sharp(srcFile, { sequentialRead: true });
685
+ const buffer = await (format === "avif" ? pipeline.avif({ quality: siblingQuality.avif }) : pipeline.webp({ quality: siblingQuality.webp })).toBuffer();
686
+ await writeFile3(siblingFile, buffer);
687
+ } catch (error) {
688
+ console.warn(
689
+ `[stratawp:images] skipped ${format} for ${rel}: ${error instanceof Error ? error.message : String(error)}`
690
+ );
680
691
  }
681
692
  }
682
693
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stratawp/vite-plugin",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "Vite plugin for WordPress theme development with StrataWP",
5
5
  "author": "Jon Imms",
6
6
  "license": "GPL-3.0-or-later",