vite-plugin-kiru 0.24.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,7 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2024-present, Rob (LankyMoose) Austen and Kiru contributors
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # vite-plugin-kiru
2
+
3
+ Vite plugin for <a href="https://kirujs.dev">Kiru</a> apps that enables HMR, devtools, and more.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm i -D vite-plugin-kiru
9
+ # or
10
+ pnpm add -D vite-plugin-kiru
11
+ ```
12
+
13
+ ### Basic Usage
14
+
15
+ ```ts
16
+ // vite.config.ts
17
+ import { defineConfig } from "vite"
18
+ import kiru from "vite-plugin-kiru"
19
+
20
+ export default defineConfig({
21
+ plugins: [kiru()],
22
+ })
23
+ ```
24
+
25
+ ### Configuration
26
+
27
+ ```ts
28
+ kiru({
29
+ // Enable or disable the Kiru devtools.
30
+ // Defaults to true in development mode.
31
+ devtools: false,
32
+
33
+ // Or provide configuration for the devtools client
34
+ devtools: {
35
+ // Path where the devtools client will be served
36
+ pathname: "/devtools", // default: "/__devtools__"
37
+ // Optional - function to format file links that will be displayed in the devtools
38
+ formatFileLink: (path, line) => `vscode://file/${path}:${line}`,
39
+ },
40
+
41
+ // Additional directories (relative to root) to include in transforms.
42
+ include: ["../shared/"],
43
+ })
44
+ ```
package/build.dev.ts ADDED
@@ -0,0 +1,29 @@
1
+ import esbuild from "esbuild"
2
+ import fs from "node:fs"
3
+
4
+ await esbuild
5
+ .context({
6
+ entryPoints: ["src/index.ts"],
7
+ bundle: true,
8
+ platform: "node",
9
+ target: "esnext",
10
+ format: "esm",
11
+ outfile: "./dist/index.js",
12
+ external: ["kiru"],
13
+ write: true,
14
+ plugins: [
15
+ {
16
+ name: "build-evts",
17
+ setup({ onEnd }) {
18
+ onEnd(() => {
19
+ console.log("[vite-plugin-kiru]: Build complete!")
20
+ fs.copyFileSync("./src/types.d.ts", "dist/index.d.ts")
21
+ })
22
+ },
23
+ },
24
+ ],
25
+ })
26
+ .then((ctx) => {
27
+ ctx.watch()
28
+ console.log("[vite-plugin-kiru]: Watching for changes...")
29
+ })
@@ -0,0 +1,57 @@
1
+ import type { Plugin } from "vite"
2
+
3
+ export type FileLinkFormatter = (path: string, line: number) => string
4
+
5
+ export interface DevtoolsOptions {
6
+ /**
7
+ * Specifies the path to the devtools app displayed via popup
8
+ * @default "/__devtools__"
9
+ */
10
+ pathname?: string
11
+
12
+ /**
13
+ * Formats the link displayed in devtools to the component's source code
14
+ * @param path the path to the file that contains the component on disk
15
+ * @param line the component's line number
16
+ * @returns {string} the formatted link
17
+ * @default (path, line) => `vscode://file/${path}:${line}`
18
+ */
19
+ formatFileLink?: FileLinkFormatter
20
+ }
21
+
22
+ export interface KiruPluginOptions {
23
+ /**
24
+ * Whether the devtools should be injected into the build during development
25
+ * @default true
26
+ */
27
+ devtools?: boolean | DevtoolsOptions
28
+
29
+ /**
30
+ * Additional directories (relative to root) to include in transforms
31
+ * @example ['../path/to/components/']
32
+ */
33
+ include?: string[]
34
+
35
+ /**
36
+ * Whether logging should be enabled
37
+ * @default false
38
+ */
39
+ loggingEnabled?: boolean
40
+
41
+ /**
42
+ * Callback for when a file is transformed
43
+ */
44
+ onFileTransformed?: (id: string, content: string) => void
45
+
46
+ /**
47
+ * Callback for when a file is excluded from transforms due to not being in project root or `include`
48
+ */
49
+ onFileExcluded?: (id: string) => void
50
+ }
51
+
52
+ /**
53
+ * Registers a callback to be fired when the HMR is triggered
54
+ */
55
+ export function onHMR(callback: () => void): void
56
+
57
+ export default function kiru(opts?: KiruPluginOptions): Plugin