@schemacompany/vite
v0.1.1
Published
Vite plugin for build-time schema injection
Readme
@schemacompany/vite
Vite plugin for build-time JSON-LD schema injection.
Installation
npm install -D @schemacompany/viteUsage
Basic Configuration
// vite.config.ts
import { defineConfig } from "vite";
import { schemaCompany } from "@schemacompany/vite";
export default defineConfig({
plugins: [
schemaCompany({
schemas: {
"/": "homepage-64-char-hash...",
"/about": "about-page-hash...",
},
}),
],
});Using a Configuration File
// vite.config.ts
import { defineConfig } from "vite";
import { schemaCompany } from "@schemacompany/vite";
export default defineConfig({
plugins: [
schemaCompany({
configFile: "./schemas.json",
}),
],
});Configuration file format:
{
"pages": [
{ "path": "/", "hash": "homepage-hash..." },
{ "path": "/about", "hash": "about-hash..." }
]
}Options
interface SchemaCompanyPluginOptions {
schemas?: Record<string, string>; // Path to hash mapping
configFile?: string; // Path to JSON config file
baseUrl?: string; // Override API base URL
position?: "head-start" | "head-end" | "body-end"; // Default: "head-end"
}How It Works
- During
buildStart, the plugin fetches all schemas from the API - Schemas are cached in memory
- During HTML transformation, schemas are injected into the appropriate pages
- Works with multi-page Vite applications
License
MIT
