@site-index/vite-plugin 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Deasilsoft
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,96 @@
1
+ # @site-index/vite-plugin
2
+
3
+ Vite integration layer for site-index serve and build pipelines.
4
+
5
+ [Repository README](../../../README.md)
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install -D @site-index/vite-plugin
11
+ ```
12
+
13
+ Requirements:
14
+
15
+ - Node.js `>=22`
16
+ - peer dependency: `vite ^8.0.10`
17
+
18
+ ## When to use
19
+
20
+ Use this package when your project already uses Vite and you want sitemap and robots.txt artifacts handled during dev and build.
21
+
22
+ ## Public exports
23
+
24
+ ```ts
25
+ export { siteIndexBuildPlugin } from "./domains/build/build.plugin.js";
26
+ export { siteIndexServePlugin } from "./domains/serve/serve.plugin.js";
27
+ export { siteIndexPlugin } from "./main.js";
28
+ ```
29
+
30
+ ## Public API
31
+
32
+ Recommended default:
33
+
34
+ - `siteIndexPlugin(options): Vite.Plugin[]`
35
+
36
+ Lower-level exports:
37
+
38
+ - `siteIndexBuildPlugin(options): Vite.Plugin`
39
+ - `siteIndexServePlugin(options): Vite.Plugin`
40
+
41
+ Options:
42
+
43
+ ```ts
44
+ type Options = Pick<CoreOptions, "siteUrl" | "extensions">;
45
+ ```
46
+
47
+ ## Behavior
48
+
49
+ `siteIndexPlugin(options)` returns:
50
+
51
+ - `siteIndexServePlugin(options)`
52
+ - `siteIndexBuildPlugin(options)`
53
+
54
+ Serve plugin:
55
+
56
+ - applies in Vite dev server
57
+ - creates runtime from the existing Vite dev server
58
+ - builds artifacts during `configureServer`
59
+ - serves generated artifact paths such as:
60
+ - `/sitemap.xml`
61
+ - `/sitemap-<name>.xml`
62
+ - `/robots.txt`
63
+ - returns headers only for `HEAD` requests
64
+ - rebuilds on hot updates when changed files are in runtime watched files
65
+ - logs warnings/errors via `@site-index/observability`
66
+
67
+ Build plugin:
68
+
69
+ - applies during Vite build
70
+ - creates runtime from resolved Vite config
71
+ - builds artifacts in `buildStart`
72
+ - emits generated artifacts as assets in `generateBundle`
73
+ - closes runtime in `closeBundle`
74
+ - logs warnings through `@site-index/observability`
75
+
76
+ ## Example
77
+
78
+ ```ts
79
+ import { defineConfig } from "vite";
80
+ import { siteIndexPlugin } from "@site-index/vite-plugin";
81
+
82
+ export default defineConfig({
83
+ plugins: [
84
+ siteIndexPlugin({
85
+ siteUrl: "https://example.com",
86
+ }),
87
+ ],
88
+ });
89
+ ```
90
+
91
+ ## Related packages
92
+
93
+ - [`@site-index/core`](../core/README.md)
94
+ - [`@site-index/vite-runtime`](../vite-runtime/README.md)
95
+ - [`@site-index/observability`](../observability/README.md)
96
+ - [`site-index`](../../site-index/README.md)
@@ -0,0 +1,5 @@
1
+ import type { Options as CoreOptions } from "@site-index/core";
2
+ import * as Vite from "vite";
3
+ type Options = Pick<CoreOptions, "siteUrl" | "extensions">;
4
+ export declare function siteIndexBuildPlugin(options: Options): Vite.Plugin;
5
+ export {};
@@ -0,0 +1,55 @@
1
+ import { Logger } from "@site-index/observability";
2
+ import { createRuntimeService } from "@site-index/vite-runtime";
3
+ import * as Vite from "vite";
4
+ import pkg from "../../../package.json" with { type: "json" };
5
+ export function siteIndexBuildPlugin(options) {
6
+ const logger = new Logger();
7
+ let runtime;
8
+ let isRuntimeClosed = false;
9
+ function getRuntime() {
10
+ if (runtime === undefined) {
11
+ throw new Error("Vite config could not be resolved");
12
+ }
13
+ return runtime;
14
+ }
15
+ async function closeRuntime() {
16
+ if (isRuntimeClosed) {
17
+ return;
18
+ }
19
+ isRuntimeClosed = true;
20
+ await runtime?.close();
21
+ }
22
+ return {
23
+ name: `${pkg.name}:build`,
24
+ apply: "build",
25
+ configResolved(config) {
26
+ runtime = createRuntimeService()
27
+ .withOptions(options)
28
+ .withViteConfig(config)
29
+ .build();
30
+ logger.configure({ writer: config.logger });
31
+ },
32
+ async buildStart() {
33
+ try {
34
+ const result = await getRuntime().buildArtifacts();
35
+ logger.warn(result.warnings);
36
+ }
37
+ catch (error) {
38
+ await closeRuntime();
39
+ throw error;
40
+ }
41
+ },
42
+ generateBundle() {
43
+ for (const artifact of getRuntime().getArtifacts()) {
44
+ this.emitFile({
45
+ type: "asset",
46
+ fileName: artifact.filePath,
47
+ source: artifact.content,
48
+ });
49
+ }
50
+ },
51
+ async closeBundle() {
52
+ await closeRuntime();
53
+ },
54
+ };
55
+ }
@@ -0,0 +1,3 @@
1
+ import type * as SiteIndex from "@site-index/core";
2
+ import * as Vite from "vite";
3
+ export declare function makeArtifactsMiddleware(artifacts: ReadonlyMap<string, SiteIndex.Artifact>): Vite.Connect.NextHandleFunction;
@@ -0,0 +1,20 @@
1
+ import * as Vite from "vite";
2
+ export function makeArtifactsMiddleware(artifacts) {
3
+ return (req, res, next) => {
4
+ if (!req.url) {
5
+ return next();
6
+ }
7
+ const path = new URL(req.url, "http://localhost").pathname;
8
+ const artifact = artifacts.get(path);
9
+ if (!artifact) {
10
+ return next();
11
+ }
12
+ res.setHeader("Content-Type", artifact.contentType);
13
+ res.statusCode = 200;
14
+ if (req.method === "HEAD") {
15
+ res.end();
16
+ return;
17
+ }
18
+ res.end(artifact.content);
19
+ };
20
+ }
@@ -0,0 +1,5 @@
1
+ import type { Options as CoreOptions } from "@site-index/core";
2
+ import * as Vite from "vite";
3
+ type Options = Pick<CoreOptions, "siteUrl" | "extensions">;
4
+ export declare function siteIndexServePlugin(options: Options): Vite.Plugin;
5
+ export {};
@@ -0,0 +1,52 @@
1
+ import { Logger } from "@site-index/observability";
2
+ import { createRuntimeService } from "@site-index/vite-runtime";
3
+ import * as Vite from "vite";
4
+ import pkg from "../../../package.json" with { type: "json" };
5
+ import { makeArtifactsMiddleware } from "./artifacts.middleware.js";
6
+ export function siteIndexServePlugin(options) {
7
+ const logger = new Logger();
8
+ let runtime;
9
+ const artifacts = new Map();
10
+ async function buildArtifacts() {
11
+ if (!runtime) {
12
+ return;
13
+ }
14
+ try {
15
+ const result = await runtime.buildArtifacts();
16
+ artifacts.clear();
17
+ for (const artifact of result.data) {
18
+ artifacts.set(`/${artifact.filePath}`, artifact);
19
+ }
20
+ logger.warn(result.warnings);
21
+ }
22
+ catch (error) {
23
+ logger.error(error);
24
+ }
25
+ }
26
+ return {
27
+ name: `${pkg.name}:serve`,
28
+ apply: "serve",
29
+ async configureServer(server) {
30
+ runtime = createRuntimeService()
31
+ .withOptions(options)
32
+ .withViteServer(server)
33
+ .build();
34
+ logger.configure({ writer: server.config.logger });
35
+ server.middlewares.use(makeArtifactsMiddleware(artifacts));
36
+ await buildArtifacts();
37
+ },
38
+ async handleHotUpdate(ctx) {
39
+ if (runtime === undefined) {
40
+ return;
41
+ }
42
+ if (!runtime.getWatchedFiles().has(ctx.file)) {
43
+ return;
44
+ }
45
+ await buildArtifacts();
46
+ },
47
+ async closeBundle() {
48
+ await runtime?.close();
49
+ runtime = undefined;
50
+ },
51
+ };
52
+ }
@@ -0,0 +1,3 @@
1
+ export { siteIndexBuildPlugin } from "./domains/build/build.plugin.js";
2
+ export { siteIndexServePlugin } from "./domains/serve/serve.plugin.js";
3
+ export { siteIndexPlugin } from "./main.js";
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { siteIndexBuildPlugin } from "./domains/build/build.plugin.js";
2
+ export { siteIndexServePlugin } from "./domains/serve/serve.plugin.js";
3
+ export { siteIndexPlugin } from "./main.js";
package/dist/main.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import type { Options as CoreOptions } from "@site-index/core";
2
+ import * as Vite from "vite";
3
+ type Options = Pick<CoreOptions, "siteUrl" | "extensions">;
4
+ export declare function siteIndexPlugin(options: Options): Vite.Plugin[];
5
+ export {};
package/dist/main.js ADDED
@@ -0,0 +1,6 @@
1
+ import * as Vite from "vite";
2
+ import { siteIndexBuildPlugin } from "./domains/build/build.plugin.js";
3
+ import { siteIndexServePlugin } from "./domains/serve/serve.plugin.js";
4
+ export function siteIndexPlugin(options) {
5
+ return [siteIndexServePlugin(options), siteIndexBuildPlugin(options)];
6
+ }
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@site-index/vite-plugin",
3
+ "version": "0.1.0",
4
+ "description": "Vite integration layer for site-index serve/build pipelines.",
5
+ "keywords": [
6
+ "site-index",
7
+ "sitemap",
8
+ "robots",
9
+ "seo",
10
+ "vite",
11
+ "plugin"
12
+ ],
13
+ "homepage": "https://github.com/Deasilsoft/site-index/tree/main/packages/@site-index/vite-plugin",
14
+ "bugs": {
15
+ "url": "https://github.com/Deasilsoft/site-index/issues"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/Deasilsoft/site-index.git",
20
+ "directory": "packages/@site-index/vite-plugin"
21
+ },
22
+ "license": "MIT",
23
+ "author": "Deasilsoft <contact@deasilsoft.com>",
24
+ "type": "module",
25
+ "exports": {
26
+ ".": {
27
+ "import": "./dist/index.js",
28
+ "types": "./dist/index.d.ts"
29
+ }
30
+ },
31
+ "main": "dist/index.js",
32
+ "types": "./dist/index.d.ts",
33
+ "files": [
34
+ "dist",
35
+ "!dist/**/*.tsbuildinfo"
36
+ ],
37
+ "scripts": {
38
+ "build": "tsc -b",
39
+ "clean": "rm -rf dist coverage",
40
+ "prepack": "npm run clean && npm run build",
41
+ "pretest": "npm pack --dry-run",
42
+ "test": "vitest run --coverage",
43
+ "pretypecheck": "npm run build",
44
+ "typecheck": "tsc --noEmit -p tsconfig.json && tsc --noEmit -p tsconfig.test.json"
45
+ },
46
+ "dependencies": {
47
+ "@site-index/core": "0.1.0",
48
+ "@site-index/observability": "0.1.0",
49
+ "@site-index/vite-runtime": "0.1.0"
50
+ },
51
+ "devDependencies": {
52
+ "@vitest/coverage-v8": "^4.1.6",
53
+ "vite": "^8.0.12",
54
+ "vitest": "^4.1.6"
55
+ },
56
+ "peerDependencies": {
57
+ "vite": "^8.0.10"
58
+ },
59
+ "engines": {
60
+ "node": ">=22"
61
+ }
62
+ }