spark-html-image 0.1.2 → 0.1.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 CHANGED
@@ -1,18 +1,17 @@
1
1
  # ⚡ spark-html-image
2
2
 
3
3
  Build-time image optimization for [spark-html](https://www.npmjs.com/package/spark-html)
4
- sites — a Vite plugin that converts your `<img>` references to **webp/avif**
5
- with a responsive `srcset`, **zero config**. No more hand-written
6
- `scripts/optimize-images.js` wired into the build command.
4
+ sites — a `spark-html-bun` pipeline step that converts your `<img>` references
5
+ to **webp/avif** with a responsive `srcset`, **zero config**. No more
6
+ hand-written `scripts/optimize-images.js` wired into the build command.
7
7
 
8
8
  ```js
9
- // vite.config.js
10
- import spark from 'spark-html/vite';
11
- import prerender from 'spark-prerender/vite';
12
- import image from 'spark-html-image';
9
+ // spark.config.js
10
+ import prerender from 'spark-prerender/bun';
11
+ import image from 'spark-html-image/bun';
13
12
 
14
13
  export default {
15
- plugins: [spark(), prerender(), image()],
14
+ pipeline: [prerender(), image()],
16
15
  };
17
16
  ```
18
17
 
@@ -39,7 +38,7 @@ External URLs, SVGs, and any `<img>` that already has a `srcset` (or sits in a
39
38
  ## Install
40
39
 
41
40
  ```bash
42
- npm install -D spark-html-image
41
+ bun add -d spark-html-image
43
42
  ```
44
43
 
45
44
  ## Options
@@ -70,6 +69,7 @@ virtual DOM, no build step required. Add only what you use.
70
69
  | Package | What it does |
71
70
  |---|---|
72
71
  | [`spark-html`](https://www.npmjs.com/package/spark-html) | The runtime — components, reactivity, stores, forms, scoped styles. 13 kB gzip, 0 deps. |
72
+ | [`spark-html-bun`](https://www.npmjs.com/package/spark-html-bun) | Dev server, bundler & preview on Bun — scoped HMR, no-build dev, post-build pipeline. |
73
73
  | [`spark-html-router`](https://www.npmjs.com/package/spark-html-router) | `<template route>` routing — nested routes/layouts, `route.query`, active links. |
74
74
  | [`spark-html-theme`](https://www.npmjs.com/package/spark-html-theme) | Dark/light/system theming in one line — persisted, no flash. |
75
75
  | [`spark-html-head`](https://www.npmjs.com/package/spark-html-head) | Reactive `<title>`/`<meta>` per route + a `head` store. |
@@ -84,6 +84,6 @@ virtual DOM, no build step required. Add only what you use.
84
84
  | [`spark-html-manifest`](https://www.npmjs.com/package/spark-html-manifest) | PWA manifest + icons + head tags (and optional service worker) from one config. |
85
85
  | [`spark-html-offline`](https://www.npmjs.com/package/spark-html-offline) | Offline URL imports — a service worker that caches CDN components. |
86
86
  | [`spark-html-sri`](https://www.npmjs.com/package/spark-html-sri) | Subresource Integrity — hash + verify assets and remote components. |
87
- | [`create-spark-html-app`](https://www.npmjs.com/package/create-spark-html-app) | Scaffold a Vite + spark-html app in one command. |
87
+ | [`create-spark-html-app`](https://www.npmjs.com/package/create-spark-html-app) | Scaffold a spark-html app in one command. |
88
88
  | [`prettier-plugin-spark`](https://www.npmjs.com/package/prettier-plugin-spark) | Prettier for components — formats `<script>`/`<style>`, markup stays byte-for-byte. |
89
89
  | [`spark-html-language-server`](https://www.npmjs.com/package/spark-html-language-server) | LSP — diagnostics, go-to-definition, prop autocomplete, hover docs. |
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "spark-html-image",
3
- "version": "0.1.2",
4
- "description": "Build-time image optimization for spark-html sites — a Vite plugin that converts <img> references to webp/avif with responsive srcset, zero config.",
3
+ "version": "0.1.4",
4
+ "description": "Build-time image optimization for spark-html sites — a spark-html-bun build step that converts <img> references to webp/avif with responsive srcset, zero config.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
7
7
  "types": "./src/index.d.ts",
@@ -11,8 +11,7 @@
11
11
  "types": "./src/index.d.ts",
12
12
  "default": "./src/index.js"
13
13
  },
14
- "./vite": {
15
- "types": "./src/index.d.ts",
14
+ "./bun": {
16
15
  "default": "./src/index.js"
17
16
  }
18
17
  },
@@ -33,7 +32,7 @@
33
32
  },
34
33
  "keywords": [
35
34
  "spark-html",
36
- "vite-plugin",
35
+ "bun",
37
36
  "images",
38
37
  "webp",
39
38
  "avif",
package/src/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * spark-html-image — build-time image optimization (Vite plugin).
2
+ * spark-html-image — build-time image optimization (spark-html-bun step).
3
3
  * Converts local raster <img> references in the built HTML (pages and
4
4
  * component fragments) to webp/avif variants with a responsive srcset.
5
5
  */
@@ -19,10 +19,8 @@ export interface SparkImageOptions {
19
19
  lazy?: boolean;
20
20
  }
21
21
 
22
- /** Vite plugin: optimize <img> references in the build output. */
22
+ /** spark-html-bun pipeline step: optimize <img> references in the build output. */
23
23
  export default function sparkImage(options?: SparkImageOptions): {
24
24
  name: string;
25
- apply: 'build';
26
- configResolved(config: unknown): void;
27
- closeBundle: { order: 'post'; handler(): Promise<void> };
25
+ run(ctx: { outDir: string }): Promise<void>;
28
26
  };
package/src/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * spark-html-image — build-time image optimization for spark-html sites.
3
3
  *
4
- * A Vite plugin: after the build (and after spark-prerender has written its
4
+ * A build step: after the build (and after spark-prerender has written its
5
5
  * per-route HTML), it scans every *.html in the out dir — pages AND
6
6
  * components — for local raster <img> references, converts each to
7
7
  * webp/avif at several widths with sharp, and rewrites the tag:
@@ -15,15 +15,16 @@
15
15
  * The original file stays in place as the src fallback, so nothing breaks in
16
16
  * a browser (or crawler) that ignores srcset. Zero config:
17
17
  *
18
- * // vite.config.js
18
+ * // spark.config.js
19
19
  * import image from 'spark-html-image';
20
- * export default { plugins: [spark(), prerender(), image()] };
20
+ * export default { pipeline: [prerender(), image()] };
21
21
  *
22
22
  * With `picture: true` it instead wraps the img in <picture> with one
23
23
  * <source> per format (useful when you enable avif).
24
24
  *
25
25
  * No core involvement — this is the same pattern as spark-prerender:
26
- * build-time only, optional, nothing added to the runtime.
26
+ * build-time only, optional, nothing added to the runtime. It's a
27
+ * spark-html-bun pipeline step: { name, run({ outDir }) }.
27
28
  */
28
29
  import { join, dirname, extname, posix } from 'node:path';
29
30
  import { readFile, writeFile, readdir, stat } from 'node:fs/promises';
@@ -84,19 +85,10 @@ export default function sparkImage(options = {}) {
84
85
  const picture = options.picture === true;
85
86
  const lazy = options.lazy !== false;
86
87
 
87
- let outDir = 'dist';
88
-
89
88
  return {
90
89
  name: 'spark-html-image',
91
- apply: 'build',
92
- configResolved(config) {
93
- if (config && config.build && config.build.outDir) outDir = config.build.outDir;
94
- },
95
- // order:'post' → runs after spark-prerender's closeBundle has written the
96
- // per-route HTML, so prerendered pages are rewritten too.
97
- closeBundle: {
98
- order: 'post',
99
- async handler() {
90
+ // Put it after prerender() in the pipeline so per-route HTML is rewritten too.
91
+ async run({ outDir }) {
100
92
  // sharp is imported lazily so merely having the plugin installed
101
93
  // never loads the native module until a build actually runs.
102
94
  let sharp;
@@ -212,7 +204,6 @@ export default function sparkImage(options = {}) {
212
204
  if (images) {
213
205
  console.log(`[spark-html-image] optimized ${images} image reference(s) across ${files} file(s) (${formats.join('+')})`);
214
206
  }
215
- },
216
207
  },
217
208
  };
218
209
  }