Open History to see the last commit
1---
2title: Vite Plugin
3id: vite-plugin
4---
5β
6The 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
7existing features built into the devtools like better console logs, server event bus, and enhanced debugging capabilities.
8β
9## Installation
10β
11To add the devtools vite plugin you need to install it as a development dependency:
12β
13```sh
14npm install -D @tanstack/devtools-vite
15```
16β
17Then add it as the *FIRST* plugin in your Vite config:
18β
19```ts
20import { devtools } from '@tanstack/devtools-vite'
21β
22export default {
23 plugins: [
24 devtools(),
25 // ... rest of your plugins here
26 ],
27}
28```
29β
30And you're done!
31β
32## Configuration
33β
34You can configure the devtools plugin by passing options to the `devtools` function:
35β
36```ts
37import { devtools } from '@tanstack/devtools-vite'
38β
39export default {
40 plugins: [
41 devtools({
42 // options here
43 }),
44 // ... rest of your plugins here
45 ],
46}
47```
48β
49### eventBusConfig
50β
51 Configuration for the event bus that the devtools use to communicate with the client
52β
53```ts
54import { devtools } from '@tanstack/devtools-vite'
55β
56export default {
57 plugins: [
58 devtools({
59 eventBusConfig: {
60 // port to run the event bus on
61 port: 1234,
62 // console log debug logs or not
63 debug: false,
64 // enables the server event bus (defaults to true), you can disable it if you're running devtools in something like storybook or vitest
65 enabled: true
66 },
67 }),
68 // ... rest of your plugins here
69 ],
70}
71β
72```
73β
74### editor
75β
76> [!IMPORTANT]
77> `editor` is used as an escape hatch to implement your own go-to-source functionality if your system/editor does not work OOTB. We use `launch-editor` under the hood which supports a lot of editors but not all. If your editor is not supported you can implement your own version here. Here is the list of supported editors: https://github.com/yyx990803/launch-editor?tab=readme-ov-file#supported-editors
78β
79The open in editor configuration which has two fields, `name` and `open`,
80`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:
81β
82 ```ts
83import { devtools } from '@tanstack/devtools-vite'
84β
85export default {
86 plugins: [
87 devtools({
88 editor: {
89 name: 'VSCode',
90 open: async (path, lineNumber, columnNumber) => {
91 const { exec } = await import('node:child_process')
92 exec(
93 // or windsurf/cursor/webstorm
94 `code -g "${(path).replaceAll('$', '\\$')}${lineNumber ? `:${lineNumber}` : ''}${columnNumber ? `:${columnNumber}` : ''}"`,
95 )
96 },
97 },
98 }),
99 // ... rest of your plugins here
100 ],
101}
102β
103```
104β
105### enhancedLogs
106β
107 Configuration for enhanced logging. Defaults to enabled.
108β
109```ts
110import { devtools } from '@tanstack/devtools-vite'
111β
112export default {
113 plugins: [
114 devtools({
115 enhancedLogs: {
116 enabled: true
117 }
118 }),
119 // ... rest of your plugins here
120 ],
121}
122```
123β
124### removeDevtoolsOnBuild
125β
126Whether to remove devtools from the production build. Defaults to true.
127β
128```ts
129import { devtools } from '@tanstack/devtools-vite'
130β
131export default {
132 plugins: [
133 devtools({
134 removeDevtoolsOnBuild: true
135 }),
136 // ... rest of your plugins here
137 ],
138}
139```
140β
141### logging
142 Whether to log information to the console. Defaults to true.
143β
144```ts
145import { devtools } from '@tanstack/devtools-vite'
146β
147export default {
148 plugins: [
149 devtools({
150 logging: true
151 }),
152 // ... rest of your plugins here
153 ],
154}
155```
156β
157### injectSource
158β
159Configuration for source injection. Defaults to enabled.
160β
161β
162```ts
163import { devtools } from '@tanstack/devtools-vite'
164β
165export default {
166 plugins: [
167 devtools({
168 injectSource: {
169 enabled: true,
170 ignore: {
171 // files to ignore source injection for
172 files: ['node_modules', /.*\.test\.(js|ts|jsx|tsx)$/],
173 // components to ignore source injection for
174 components: ['YourComponent', /.*Lazy$/],
175 },
176 }
177 }),
178 // ... rest of your plugins here
179 ],
180}
181```
182β
183### consolePiping
184β
185Configuration for bidirectional console piping between client and server. When enabled, console logs from the client will appear in your terminal, and server logs will appear in the browser console. Defaults to enabled.
186β
187```ts
188import { devtools } from '@tanstack/devtools-vite'
189β
190export default {
191 plugins: [
192 devtools({
193 consolePiping: {
194 // Whether to enable console piping (defaults to true)
195 enabled: true,
196 // Which console methods to pipe (defaults to all)
197 levels: ['log', 'warn', 'error', 'info', 'debug'],
198 }
199 }),
200 // ... rest of your plugins here
201 ],
202}
203```
204β
205## Features
206β
207The Vite plugin is composed of several sub-plugins, each handling a specific concern:
208β
209```mermaid
210graph TD
211 vite["@tanstack/devtools-vite"]
212 vite --> source["Source Injection<br/><i>AST β data-tsd-source attrs</i>"]
213 vite --> server["Server Event Bus<br/><i>WebSocket + SSE transport</i>"]
214 vite --> strip["Production Stripping<br/><i>Remove devtools on build</i>"]
215 vite --> pipe["Console Piping<br/><i>Client β Server logs</i>"]
216 vite --> logs["Enhanced Logs<br/><i>Source location in console</i>"]
217 vite --> market["Marketplace<br/><i>Install plugins via UI</i>"]
218 vite --> connect["Connection Injection<br/><i>Port/host placeholders</i>"]
219```
220β
221### Go to Source
222β
223The "Go to Source" feature lets you click on any element in your browser and open its source file in your editor at the exact line where it's defined. It works by injecting `data-tsd-source` attributes into your components via an AST transformation during development. These attributes encode the file path and line number of each element.
224β
225To use it, activate the source inspector by holding the inspect hotkey (default: Shift+Alt+Ctrl/Meta). An overlay will highlight elements under your cursor and display their source location. Clicking on a highlighted element opens the corresponding file in your editor at the exact line, powered by `launch-editor` under the hood.
226β
227For a complete guide on configuration and usage, see the [Source Inspector](./source-inspector) docs.
228β
229### Console Piping
230β
231When enabled (default), `console.log()` and other console methods in the browser are piped to your terminal, and server-side console output appears in the browser console. This is particularly useful when debugging SSR or API routes β you see all logs in one place without switching between terminal and browser. Configure which log levels are piped via `consolePiping.levels`.
232β
233### Enhanced Logs
234β
235Console logs are enhanced with clickable source locations. In the browser console, each log shows the file and line number where it originated. Click to open the source file in your editor. Enable/disable via the `enhancedLogs` config option.
236β
237### Production Build Stripping
238β
239By default (`removeDevtoolsOnBuild: true`), the Vite plugin replaces all devtools imports with empty modules in production builds. This includes:
240- `@tanstack/react-devtools`
241- `@tanstack/vue-devtools`
242- `@tanstack/solid-devtools`
243- `@tanstack/preact-devtools`
244- `@tanstack/devtools`
245β
246This ensures zero devtools code reaches production. Set `removeDevtoolsOnBuild: false` to keep devtools in production (see [Production](./production) docs).
247β
248### Plugin Marketplace
249β
250The Vite plugin enables the in-devtools plugin marketplace. When you browse available plugins in the devtools Settings tab and click "Install", the Vite plugin handles the npm/pnpm/yarn installation and automatically injects the plugin import into your devtools setup file. This only works during development with the Vite dev server running.