@cadamsdev/vite-plugin-wc-devtools 0.0.1

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 ADDED
@@ -0,0 +1,79 @@
1
+ # Vite Web Component Dev Tools Plugin
2
+
3
+ A Vite plugin that provides developer tools for inspecting and debugging web components in your application.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install vite-plugin --save-dev
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ Add the plugin to your Vite configuration:
14
+
15
+ ```javascript
16
+ // vite.config.js
17
+ import { defineConfig } from 'vite';
18
+ import { webComponentDevTools } from 'vite-plugin';
19
+
20
+ export default defineConfig({
21
+ plugins: [
22
+ webComponentDevTools({
23
+ position: 'bottom-right'
24
+ })
25
+ ]
26
+ });
27
+ ```
28
+
29
+ ### Options
30
+
31
+ - **`enabled`** (boolean, default: `true`): Enable or disable the dev tools.
32
+ - **`position`** (string, default: `'bottom-right'`): Position of the dev tools button. Options: `'top-left'`, `'top-right'`, `'bottom-left'`, `'bottom-right'`.
33
+ - **`queryParam`** (string, optional): Query parameter name to check for enabling dev tools. If specified, the dev tools button will only show when this query param is present in the URL (e.g., `?debug`).
34
+ - **`includeInProduction`** (boolean, default: `false`): Include the dev tools in production builds. By default, dev tools are only included in development mode.
35
+
36
+ ### Example with Options
37
+
38
+ ```javascript
39
+ webComponentDevTools({
40
+ enabled: true,
41
+ position: 'top-right',
42
+ queryParam: 'debug',
43
+ includeInProduction: false
44
+ })
45
+ ```
46
+
47
+ ### Production Usage
48
+
49
+ By default, the dev tools are only included in development builds. If you want to include them in production builds (e.g., for staging environments or internal testing), set `includeInProduction: true`:
50
+
51
+ ```javascript
52
+ webComponentDevTools({
53
+ includeInProduction: true,
54
+ queryParam: 'devtools' // Recommended: use with queryParam to hide by default
55
+ })
56
+ ```
57
+
58
+ **Note:** When using in production, it's recommended to combine `includeInProduction` with `queryParam` to ensure the dev tools are only visible when explicitly requested via a URL parameter.
59
+
60
+ ## Features
61
+
62
+ - 🔍 Inspect web component properties and attributes
63
+ - 🎨 View and edit CSS custom properties
64
+ - 📊 Monitor component lifecycle events
65
+ - ♿ Check accessibility compliance
66
+ - 🔄 Track component renders and performance
67
+ - 🌳 Visualize component hierarchy
68
+
69
+ ## Requirements
70
+
71
+ - Vite 4.x or higher
72
+
73
+ ## How It Works
74
+
75
+ The plugin automatically injects the dev tools client script into your HTML during the build process when in development mode. The dev tools will appear as a floating button in your browser that you can click to open the inspection panel.
76
+
77
+ ## License
78
+
79
+ MIT
@@ -0,0 +1,27 @@
1
+ import { Plugin } from "vite";
2
+
3
+ //#region src/index.d.ts
4
+ interface WebComponentDevToolsOptions {
5
+ /**
6
+ * Enable the dev tools (default: true in dev mode only)
7
+ */
8
+ enabled?: boolean;
9
+ /**
10
+ * Position of the dev tools button (default: 'bottom-right')
11
+ */
12
+ position?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
13
+ /**
14
+ * Query parameter name to check for enabling dev tools
15
+ * If specified, the dev tools button will only show when this query param is present
16
+ * Example: queryParam: 'debug' will show dev tools when ?debug is in the URL
17
+ */
18
+ queryParam?: string;
19
+ /**
20
+ * Include the dev tools in production builds (default: false)
21
+ * By default, dev tools are only included in development mode
22
+ */
23
+ includeInProduction?: boolean;
24
+ }
25
+ declare function webComponentDevTools(options?: WebComponentDevToolsOptions): Plugin;
26
+ //#endregion
27
+ export { WebComponentDevToolsOptions, webComponentDevTools as default, webComponentDevTools };
package/dist/index.mjs ADDED
@@ -0,0 +1,43 @@
1
+ import { createRequire } from "node:module";
2
+ import { readFileSync } from "node:fs";
3
+
4
+ //#region src/index.ts
5
+ const require = createRequire(import.meta.url);
6
+ function webComponentDevTools(options = {}) {
7
+ const { enabled = true, position = "bottom-right", queryParam, includeInProduction = false } = options;
8
+ let isDev = false;
9
+ let clientScript = null;
10
+ return {
11
+ name: "vite-plugin",
12
+ configResolved(config) {
13
+ isDev = config.mode === "development";
14
+ if (enabled && (isDev || includeInProduction)) try {
15
+ clientScript = readFileSync(require.resolve("client/client"), "utf-8");
16
+ } catch (error) {
17
+ console.error("[vite-plugin] Failed to load client script:", error);
18
+ }
19
+ },
20
+ transformIndexHtml(html) {
21
+ if (!enabled || !isDev && !includeInProduction || !clientScript) return html;
22
+ return {
23
+ html,
24
+ tags: [{
25
+ tag: "script",
26
+ attrs: { type: "module" },
27
+ children: `
28
+ window.__WC_DEVTOOLS_CONFIG__ = ${JSON.stringify({
29
+ position,
30
+ queryParam
31
+ })};
32
+ ${clientScript}
33
+ `,
34
+ injectTo: "body"
35
+ }]
36
+ };
37
+ }
38
+ };
39
+ }
40
+ var src_default = webComponentDevTools;
41
+
42
+ //#endregion
43
+ export { src_default as default, webComponentDevTools };
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@cadamsdev/vite-plugin-wc-devtools",
3
+ "version": "0.0.1",
4
+ "description": "A Vite plugin that provides developer tools for inspecting web components",
5
+ "keywords": [
6
+ "custom-elements",
7
+ "dev-tools",
8
+ "plugin",
9
+ "vite",
10
+ "web-components"
11
+ ],
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "type": "module",
16
+ "main": "./dist/index.mjs",
17
+ "module": "./dist/index.mjs",
18
+ "types": "./dist/index.d.mts",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.mts",
22
+ "import": "./dist/index.mjs"
23
+ }
24
+ },
25
+ "scripts": {
26
+ "build": "tsdown",
27
+ "dev": "tsdown --watch"
28
+ },
29
+ "dependencies": {
30
+ "@cadamsdev/wc-devtools-client": "0.0.0"
31
+ },
32
+ "devDependencies": {
33
+ "@types/node": "^25.1.0",
34
+ "tsdown": "^0.20.1",
35
+ "typescript": "^5.3.3",
36
+ "vite": "^5.0.0"
37
+ },
38
+ "peerDependencies": {
39
+ "vite": "^4.0.0 || ^5.0.0"
40
+ }
41
+ }