vite-plugin-kiru 0.28.2 → 0.29.0-preview.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,6 +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, and more.
3
+ Vite plugin for <a href="https://kirujs.dev">Kiru</a> apps that enables HMR, devtools, file-based routing, and SSG/SSR.
4
4
 
5
5
  ## Installation
6
6
 
@@ -10,7 +10,7 @@ npm i -D vite-plugin-kiru
10
10
  pnpm add -D vite-plugin-kiru
11
11
  ```
12
12
 
13
- ### Basic Usage
13
+ ## Basic Usage
14
14
 
15
15
  ```ts
16
16
  // vite.config.ts
@@ -22,7 +22,7 @@ export default defineConfig({
22
22
  })
23
23
  ```
24
24
 
25
- ### Configuration
25
+ ## Configuration
26
26
 
27
27
  ```ts
28
28
  kiru({
@@ -40,5 +40,45 @@ kiru({
40
40
 
41
41
  // Additional directories (relative to root) to include in transforms.
42
42
  include: ["../shared/"],
43
+
44
+ // Enable logging for debugging
45
+ loggingEnabled: true,
46
+
47
+ // App configuration for file-based routing
48
+ app: {
49
+ baseUrl: "/", // Base URL for the app
50
+ dir: "src/pages", // Directory containing pages
51
+ document: "document.tsx", // Document component file
52
+ page: "index.{tsx,jsx}", // Page component pattern
53
+ layout: "layout.{tsx,jsx}", // Layout component pattern
54
+ },
55
+
56
+ // Callbacks
57
+ onFileTransformed: (id, content) => {
58
+ console.log(`Transformed: ${id}`)
59
+ },
60
+ onFileExcluded: (id) => {
61
+ console.log(`Excluded: ${id}`)
62
+ },
43
63
  })
44
64
  ```
65
+
66
+ ## Features
67
+
68
+ - **File-based routing**: Automatic route generation from your pages directory
69
+ - **SSR/SSG**: Server-side rendering and static site generation
70
+ - **HMR**: Hot module replacement for fast development
71
+ - **Devtools**: Built-in development tools for debugging
72
+ - **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
@@ -2,12 +2,58 @@ import type { ESBuildOptions, Plugin } from "vite"
2
2
 
3
3
  export type FileLinkFormatter = (path: string, line: number) => string
4
4
 
5
+ export interface SSGBuildOptions {
6
+ /**
7
+ * The max number of pages to render/load concurrently
8
+ * @default 100
9
+ */
10
+ maxConcurrentRenders?: number
11
+ }
12
+
13
+ export interface SSGOptions {
14
+ /**
15
+ * The base URL of the app
16
+ * @default "/"
17
+ */
18
+ baseUrl?: string
19
+ /**
20
+ * The directory of the app
21
+ * @default "src/pages"
22
+ */
23
+ dir?: string
24
+ /**
25
+ * The name of the document component
26
+ * @default "document.tsx"
27
+ */
28
+ document?: string
29
+ /**
30
+ * The filename of page components to search for
31
+ * @default "index.{tsx,jsx}"
32
+ */
33
+ page?: string
34
+ /**
35
+ * The filename of layout components to search for
36
+ * @default "layout.{tsx,jsx}"
37
+ */
38
+ layout?: string
39
+ /**
40
+ * Enable transitions for all routes and loading states
41
+ * @default false
42
+ */
43
+ transition?: boolean
44
+
45
+ /**
46
+ * Options for build
47
+ */
48
+ build?: SSGBuildOptions
49
+ }
50
+
5
51
  export interface DevtoolsOptions {
6
52
  /**
7
53
  * Specifies the path to the devtools app displayed via popup
8
54
  * @default "/__devtools__"
9
55
  */
10
- pathname?: string
56
+ dtClientPathname?: string
11
57
 
12
58
  /**
13
59
  * Formats the link displayed in devtools to the component's source code
@@ -47,6 +93,21 @@ export interface KiruPluginOptions {
47
93
  * Callback for when a file is excluded from transforms due to not being in project root or `include`
48
94
  */
49
95
  onFileExcluded?: (id: string) => void
96
+
97
+ /**
98
+ * Options for SSG
99
+ * @example
100
+ * ```ts
101
+ * ssg: {
102
+ * dir: "./src/app",
103
+ * document: "document.tsx",
104
+ * page: "index.{tsx,jsx}",
105
+ * layout: "layout.{tsx,jsx}",
106
+ * transition: true
107
+ * }
108
+ * ```
109
+ */
110
+ ssg?: SSGOptions | true
50
111
  }
51
112
 
52
113
  export const defaultEsBuildOptions: ESBuildOptions