vite-plugin-kiru 0.29.10 → 0.30.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/README.md CHANGED
@@ -1,14 +1,6 @@
1
1
  # vite-plugin-kiru
2
2
 
3
- Vite plugin for <a href="https://kirujs.dev">Kiru</a> apps that enables HMR, devtools, file-based routing, and SSG/SSR.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- npm i -D vite-plugin-kiru
9
- # or
10
- pnpm add -D vite-plugin-kiru
11
- ```
3
+ Vite plugin for <a href="https://kirujs.dev">Kiru</a> apps that enables HMR, devtools, and SSG with file-based routing & sitemap generation.
12
4
 
13
5
  ## Basic Usage
14
6
 
@@ -60,25 +52,106 @@ kiru({
60
52
  onFileExcluded: (id) => {
61
53
  console.log(`Excluded: ${id}`)
62
54
  },
55
+
56
+ // Static Site Generation (SSG) configuration
57
+ ssg: {
58
+ // Base URL for the app
59
+ baseUrl: "/",
60
+ // Directory containing pages
61
+ dir: "./src/pages",
62
+ // Document component filename pattern
63
+ document: "document.{tsx,jsx}",
64
+ // Page component filename pattern
65
+ page: "index.{tsx,jsx}",
66
+ // Layout component filename pattern
67
+ layout: "layout.{tsx,jsx}",
68
+ // Enable view transitions for route changes and page loaders
69
+ transition: true,
70
+ // Build options
71
+ build: {
72
+ // Maximum number of pages to render concurrently
73
+ maxConcurrentRenders: 100,
74
+ },
75
+ // Sitemap generation options
76
+ sitemap: {
77
+ // Domain for sitemap URLs (required)
78
+ domain: "https://example.com",
79
+ // Default last modified date for all URLs
80
+ lastmod: new Date(),
81
+ // Default change frequency (hourly | daily | weekly | monthly | yearly | never)
82
+ changefreq: "weekly", // default: "weekly"
83
+ // Default priority (0.0 to 1.0)
84
+ priority: 0.5, // default: 0.5
85
+ // Per-route overrides
86
+ overrides: {
87
+ "/": {
88
+ changefreq: "daily",
89
+ priority: 0.8,
90
+ lastmod: new Date("2024-01-01"),
91
+ // Images to include for this route
92
+ images: ["/images/hero.png"],
93
+ // Videos to include for this route
94
+ videos: [
95
+ {
96
+ title: "Product Demo",
97
+ thumbnail_loc: "/images/video-thumbnail.png",
98
+ description: "A demonstration of our product features.",
99
+ },
100
+ ],
101
+ },
102
+ "/blog": {
103
+ changefreq: "weekly",
104
+ priority: 0.7,
105
+ },
106
+ },
107
+ },
108
+ },
109
+
110
+ // Or, if you want to enable SSG with default configuration:
111
+ ssg: true,
112
+ // (this will not include sitemap generation as it requires manual configuration)
63
113
  })
64
114
  ```
65
115
 
116
+ ## Static Site Generation (SSG)
117
+
118
+ The plugin supports static site generation with configurable sitemap creation. When SSG is enabled, all routes are pre-rendered at build time and a `sitemap.xml` file is generated if configured.
119
+
120
+ ### Sitemap Generation
121
+
122
+ The sitemap feature generates a `sitemap.xml` file in your build output with all discovered routes (excluding 404 pages).
123
+
124
+ **Features:**
125
+
126
+ - Automatic route discovery from your file structure
127
+ - Configurable default `changefreq`, `priority`, and `lastmod` for all routes
128
+ - Per-route overrides for fine-grained control
129
+ - Support for images and videos (Google sitemap extensions)
130
+
131
+ **Example:**
132
+
133
+ ```ts
134
+ ssg: {
135
+ sitemap: {
136
+ domain: "https://kirujs.dev",
137
+ changefreq: "weekly",
138
+ priority: 0.5,
139
+ overrides: {
140
+ "/": {
141
+ changefreq: "daily",
142
+ priority: 0.8,
143
+ images: ["/images/kiru.png"],
144
+ },
145
+ },
146
+ },
147
+ }
148
+ ```
149
+
150
+ This will generate a `sitemap.xml` file in `dist/client/sitemap.xml` with all your routes properly formatted.
151
+
66
152
  ## Features
67
153
 
68
- - **File-based routing**: Automatic route generation from your pages directory
69
- - **SSR/SSG**: Server-side rendering and static site generation
154
+ - **SSG + file-based routing**: Automatic route discovery, static site and sitemap generation
70
155
  - **HMR**: Hot module replacement for fast development
71
156
  - **Devtools**: Built-in development tools for debugging
72
157
  - **TypeScript**: Full TypeScript support with proper type definitions
73
-
74
- ## Architecture
75
-
76
- The plugin is organized into focused modules:
77
-
78
- - `virtual-modules.ts` - Virtual module generation for routing
79
- - `dev-server.ts` - Development server SSR handling
80
- - `preview-server.ts` - Preview server middleware
81
- - `devtools.ts` - Development tools integration
82
- - `ssg.ts` - Static site generation
83
- - `config.ts` - Configuration management
84
- - `utils.ts` - Shared utilities
package/dist/index.d.ts CHANGED
@@ -10,6 +10,86 @@ export interface SSGBuildOptions {
10
10
  maxConcurrentRenders?: number
11
11
  }
12
12
 
13
+ export type SSGSitemapChangefreq =
14
+ // | "always"
15
+ "hourly" | "daily" | "weekly" | "monthly" | "yearly" | "never"
16
+
17
+ export interface SSGSitemapVideo {
18
+ title: string
19
+ thumbnail_loc: string
20
+ description?: string
21
+ }
22
+
23
+ export interface SSGSitemapOverride {
24
+ /**
25
+ * Change frequency override for this route
26
+ * @default "weekly"
27
+ */
28
+ changefreq?: SSGSitemapChangefreq
29
+ /**
30
+ * Priority override for this route (0.0 to 1.0)
31
+ * @default 0.5
32
+ */
33
+ priority?: number
34
+ /**
35
+ * Last modified date override for this route
36
+ */
37
+ lastmod?: Date
38
+ /**
39
+ * Images to include for this route
40
+ * @example ["/images/kiru.png"]
41
+ */
42
+ images?: string[]
43
+ /**
44
+ * Videos to include for this route
45
+ * @example
46
+ * ```ts
47
+ * videos: [
48
+ * {
49
+ * title: "Kiru",
50
+ * thumbnail_loc: "/images/kiru.png",
51
+ * description: "Kiru is a framework for building web applications."
52
+ * }
53
+ * ]
54
+ * ```
55
+ */
56
+ videos?: Array<SSGSitemapVideo>
57
+ }
58
+
59
+ export interface SSGSitemapOptions {
60
+ /**
61
+ * The domain to use for sitemap URLs
62
+ * @example "https://example.com"
63
+ */
64
+ domain: string
65
+ /**
66
+ * Default last modified date for all URLs
67
+ */
68
+ lastmod?: Date
69
+ /**
70
+ * Default change frequency for all URLs
71
+ * @default "weekly"
72
+ */
73
+ changefreq?: SSGSitemapChangefreq
74
+ /**
75
+ * Default priority for all URLs (0.0 to 1.0)
76
+ * @default 0.5
77
+ */
78
+ priority?: number
79
+ /**
80
+ * Per-route overrides for sitemap entries
81
+ * @example
82
+ * ```ts
83
+ * overrides: {
84
+ * "/": {
85
+ * changefreq: "never",
86
+ * priority: 0.8,
87
+ * },
88
+ * }
89
+ */
90
+ overrides?: Record<string, SSGSitemapOverride>
91
+ }
92
+
13
93
  export interface SSGOptions {
14
94
  /**
15
95
  * The base URL of the app
@@ -42,6 +122,11 @@ export interface SSGOptions {
42
122
  */
43
123
  transition?: boolean
44
124
 
125
+ /**
126
+ * Options for sitemap generation
127
+ */
128
+ sitemap?: SSGSitemapOptions
129
+
45
130
  /**
46
131
  * Options for build
47
132
  */