Skip to content

Commit a7c5601

Browse files
Feat/vite plugin (#53)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent af35d92 commit a7c5601

29 files changed

+636
-21
lines changed

.changeset/two-paths-remain.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@tanstack/devtools-vite': patch
3+
'@tanstack/devtools-event-bus': patch
4+
---
5+
6+
Add devtools vite plugin for enhanced functionalities

docs/installation.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Only install one of the following packages depending on your use case:
1111

1212
```sh
1313
npm install @tanstack/react-devtools
14+
npm install -D @tanstack/devtools-vite
1415
```
1516

1617
TanStack Devtools is compatible with React v16.8+
@@ -19,6 +20,7 @@ TanStack Devtools is compatible with React v16.8+
1920

2021
```sh
2122
npm install @tanstack/solid-devtools
23+
npm install -D @tanstack/devtools-vite
2224
```
2325

2426
TanStack Devtools is compatible with Solid v1.9.5+

docs/quick-start.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ TanStack Devtools is a framework-agnostic devtool for managing and debugging *de
77

88
To get up and running install the correct adapter for your framework:
99

10-
- **React**: `npm install @tanstack/react-devtools`
11-
- **Solid**: `npm install @tanstack/solid-devtools`
10+
- **React**: `npm install @tanstack/react-devtools @tanstack/devtools-vite`
11+
- **Solid**: `npm install @tanstack/solid-devtools @tanstack/devtools-vite`
1212

1313
Then import the devtools into the root of your application:
1414

@@ -25,6 +25,19 @@ function App() {
2525
}
2626
```
2727

28+
And plug the vite plugin as the first plugin in your plugin array in `vite.config.ts`:
29+
30+
```javascript
31+
import { devtools } from '@tanstack/devtools-vite'
32+
33+
export default {
34+
plugins: [
35+
devtools(),
36+
// ... rest of your plugins here
37+
],
38+
}
39+
```
40+
2841
And you're done! If you want to add custom plugins, you can do so by using the `plugins` prop:
2942

3043
```javascript

docs/vite-plugin.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
title: Vite Plugin
3+
id: vite-plugin
4+
---
5+
6+
The Vite Plugin for TanStack Devtools provides a seamless integration for using the devtools in your Vite-powered applications. With this plugin, you get complementary features on top of the
7+
existing features built into the devtools like better console logs, server event bus, and enhanced debugging capabilities.
8+
9+
## Installation
10+
11+
To add the devtools vite plugin you need to install it as a development dependency:
12+
13+
```sh
14+
npm install -D @tanstack/devtools-vite
15+
```
16+
17+
Then add it as the *FIRST* plugin in your Vite config:
18+
19+
```javascript
20+
import { devtools } from '@tanstack/devtools-vite'
21+
22+
export default {
23+
plugins: [
24+
devtools(),
25+
// ... rest of your plugins here
26+
],
27+
}
28+
```
29+
30+
And you're done!
31+
32+
## Configuration
33+
34+
You can configure the devtools plugin by passing options to the `devtools` function:
35+
36+
```javascript
37+
import { devtools } from '@tanstack/devtools-vite'
38+
39+
export default {
40+
plugins: [
41+
devtools({
42+
// options here
43+
}),
44+
// ... rest of your plugins here
45+
],
46+
}
47+
```
48+
49+
- `eventBusConfig` - Configuration for the event bus that the devtools use to communicate with the client
50+
51+
```ts
52+
{
53+
eventBusConfig: {
54+
// port to run the event bus on
55+
port: 1234,
56+
// console log debug logs or not
57+
debug: false
58+
},
59+
}
60+
```
61+
62+
- `appDir` - The directory where the react router app is located. Defaults to the "./src" relative to where vite.config is being defined.
63+
64+
```javascript
65+
{
66+
appDir: './src',
67+
}
68+
```
69+
70+
- `editor` - The open in editor configuration which has two fields, `name` and `open`,
71+
`name` is the name of your editor, and `open` is a function that opens the editor with the given file and line number. You can implement your version for your editor as follows:
72+
73+
```ts
74+
const open = (file: string, line: number) => {
75+
// implement your editor opening logic here
76+
}
77+
78+
{
79+
editor: {
80+
name: 'vscode',
81+
open
82+
}
83+
}
84+
```
85+
86+
87+
- `enhancedLogs` - Configuration for enhanced logging. Defaults to enabled.
88+
89+
```ts
90+
{
91+
enhancedLogs: {
92+
enabled: true
93+
}
94+
}

examples/react/basic/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"zod": "^4.0.14"
2121
},
2222
"devDependencies": {
23+
"@tanstack/devtools-vite": "0.2.2",
2324
"@types/react": "^19.1.2",
2425
"@types/react-dom": "^19.1.2",
2526
"@vitejs/plugin-react": "^4.5.2",

examples/react/basic/vite.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { defineConfig } from 'vite'
22
import react from '@vitejs/plugin-react'
3-
3+
import { devtools } from '@tanstack/devtools-vite'
44
// https://vite.dev/config/
55
export default defineConfig({
66
plugins: [
7+
devtools(),
78
react({
89
// babel: {
910
// plugins: [['babel-plugin-react-compiler', { target: '19' }]],

examples/react/start/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"zod": "^4.0.14"
3737
},
3838
"devDependencies": {
39+
"@tanstack/devtools-vite": "0.2.2",
3940
"@testing-library/dom": "^10.4.0",
4041
"@testing-library/react": "^16.2.0",
4142
"@types/react": "^19.1.2",

examples/react/start/src/components/devtools.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export default function DevtoolsExample() {
1313
<QueryClientProvider client={queryClient}>
1414
<TanStackDevtools
1515
eventBusConfig={{
16-
debug: true,
16+
debug: false,
17+
connectToServerBus: true,
1718
}}
1819
plugins={[
1920
{

examples/react/start/src/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class QueryDevtoolsClient extends EventClient<EventMap> {
1919
constructor() {
2020
super({
2121
pluginId: 'query-devtools',
22-
debug: true,
22+
debug: false,
2323
})
2424
}
2525
}

examples/react/start/src/routes/__root.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const Route = createRootRoute({
2929
})
3030

3131
function RootDocument({ children }: { children: React.ReactNode }) {
32+
console.log('hello in root document')
3233
return (
3334
<html lang="en">
3435
<head>

0 commit comments

Comments
 (0)