vite-plugin-component-ref 1.0.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 +21 -0
- package/README.md +85 -0
- package/dist/index.d.mts +16 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +15000 -0
- package/dist/index.mjs +14994 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Antigravity User
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# vite-plugin-component-ref
|
|
2
|
+
|
|
3
|
+
A powerful Vite plugin that automatically tags React components with source reference attributes. This enables a seamless **"Alt + Click"** experience to jump from your browser directly to the corresponding line in your IDE.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🎯 **Automatic Tagging**: Injects `ref-id`, `ref-component`, `ref-line`, etc., into your JSX elements.
|
|
8
|
+
- ⚡ **Click-to-Open**: Press `Alt + Click` in the browser to instantly open the source file in your editor at the exact line.
|
|
9
|
+
- 🤖 **Smart Editor Defaults**: Built-in support for `antigravity`, `cursor`, and `vscode` (no manual configuration needed).
|
|
10
|
+
- 🛠️ **Flexible Configuration**: Full control over what attributes to inject and which files to include/exclude.
|
|
11
|
+
- 👥 **Team Friendly**: Environment variable overrides allow each developer to use their preferred editor.
|
|
12
|
+
- 🛡️ **Production Safe**: Automatically disables itself in production builds to keep your bundle clean.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install vite-plugin-component-ref --save-dev
|
|
18
|
+
# or
|
|
19
|
+
yarn add vite-plugin-component-ref --dev
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
|
+
|
|
24
|
+
Add the plugin to your `vite.config.ts`:
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { defineConfig } from 'vite';
|
|
28
|
+
import react from '@vitejs/plugin-react';
|
|
29
|
+
import { componentRefTagger } from 'vite-plugin-component-ref';
|
|
30
|
+
|
|
31
|
+
export default defineConfig({
|
|
32
|
+
plugins: [
|
|
33
|
+
componentRefTagger({
|
|
34
|
+
editor: 'antigravity', // Automatically handles line-positioning flags
|
|
35
|
+
}),
|
|
36
|
+
react(),
|
|
37
|
+
],
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Configuration Options
|
|
42
|
+
|
|
43
|
+
| Option | Type | Default | Description |
|
|
44
|
+
| :--- | :--- | :--- | :--- |
|
|
45
|
+
| `prefix` | `string` | `"data-ref"` | Prefix for the injected attributes (e.g., `ref-id`). |
|
|
46
|
+
| `attributes` | `string[]` | `['id', 'name', 'path', 'line', 'file', 'component']` | Which attributes to inject. |
|
|
47
|
+
| `basePath` | `string` | `"src"` | The base directory for calculating relative paths. |
|
|
48
|
+
| `include` | `(string \| RegExp)[]` | `['.tsx', '.jsx']` | Files to process. |
|
|
49
|
+
| `exclude` | `(string \| RegExp)[]` | `['node_modules', 'main.tsx']` | Files to ignore. |
|
|
50
|
+
| `enabled` | `boolean` | `true` | Enable or disable the plugin. |
|
|
51
|
+
| `editor` | `string` | `"code"` | Your preferred editor (e.g., `antigravity`, `cursor`, `code`). |
|
|
52
|
+
| `shouldTag` | `(comp, path) => boolean`| `() => true` | Custom filter for specific components or files. |
|
|
53
|
+
| `openInEditor`| `(path, line) => void` | `undefined` | Custom callback for manual editor integration. |
|
|
54
|
+
|
|
55
|
+
## Advanced Usage
|
|
56
|
+
|
|
57
|
+
### Custom Editor Command
|
|
58
|
+
If your editor needs a specific format, use `{file}` and `{line}` placeholders:
|
|
59
|
+
```typescript
|
|
60
|
+
componentRefTagger({
|
|
61
|
+
editor: 'my-editor --goto {file}:{line}'
|
|
62
|
+
})
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Team Collaboration (Environment Overrides)
|
|
66
|
+
Developers can override the project-wide editor setting by adding a variable to their `.env.local`:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
# .env.local
|
|
70
|
+
COMPONENT_REF_EDITOR=cursor
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
The plugin will automatically detect it's Cursor and use the correct positioning flags!
|
|
74
|
+
|
|
75
|
+
### Selective Tagging
|
|
76
|
+
Only tag components starting with "User":
|
|
77
|
+
```typescript
|
|
78
|
+
componentRefTagger({
|
|
79
|
+
shouldTag: (name) => name.startsWith('User')
|
|
80
|
+
})
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## License
|
|
84
|
+
|
|
85
|
+
MIT © [Antigravity User]
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
interface PluginOptions {
|
|
4
|
+
prefix?: string;
|
|
5
|
+
attributes?: ("id" | "name" | "path" | "line" | "file" | "component")[];
|
|
6
|
+
basePath?: string;
|
|
7
|
+
include?: string | RegExp | (string | RegExp)[];
|
|
8
|
+
exclude?: string | RegExp | (string | RegExp)[];
|
|
9
|
+
enabled?: boolean;
|
|
10
|
+
shouldTag?: (componentName: string, filePath: string) => boolean;
|
|
11
|
+
editor?: string;
|
|
12
|
+
openInEditor?: (filePath: string, line: number) => void;
|
|
13
|
+
}
|
|
14
|
+
declare function componentRefTagger(options?: PluginOptions): Plugin;
|
|
15
|
+
|
|
16
|
+
export { type PluginOptions, componentRefTagger };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
interface PluginOptions {
|
|
4
|
+
prefix?: string;
|
|
5
|
+
attributes?: ("id" | "name" | "path" | "line" | "file" | "component")[];
|
|
6
|
+
basePath?: string;
|
|
7
|
+
include?: string | RegExp | (string | RegExp)[];
|
|
8
|
+
exclude?: string | RegExp | (string | RegExp)[];
|
|
9
|
+
enabled?: boolean;
|
|
10
|
+
shouldTag?: (componentName: string, filePath: string) => boolean;
|
|
11
|
+
editor?: string;
|
|
12
|
+
openInEditor?: (filePath: string, line: number) => void;
|
|
13
|
+
}
|
|
14
|
+
declare function componentRefTagger(options?: PluginOptions): Plugin;
|
|
15
|
+
|
|
16
|
+
export { type PluginOptions, componentRefTagger };
|