diff --git a/.changeset/cuddly-mammals-cough.md b/.changeset/cuddly-mammals-cough.md new file mode 100644 index 00000000..edbebfe1 --- /dev/null +++ b/.changeset/cuddly-mammals-cough.md @@ -0,0 +1,7 @@ +--- +'@tanstack/devtools-event-client': patch +'@tanstack/react-devtools': patch +'@tanstack/solid-devtools': patch +--- + +exclude from production by default diff --git a/examples/react/start/package.json b/examples/react/start/package.json index 2de1031f..46c4db4b 100644 --- a/examples/react/start/package.json +++ b/examples/react/start/package.json @@ -7,6 +7,7 @@ "start": "node .output/server/index.mjs", "serve": "vite preview", "test": "vitest run", + "preview": "vite preview", "db:migrate": "prisma migrate dev --name init", "db:reset": " prisma migrate reset", "db:gen": "prisma generate", @@ -35,7 +36,6 @@ "zod": "^4.0.14" }, "devDependencies": { - "@tanstack/devtools": "^0.4.0", "@testing-library/dom": "^10.4.0", "@testing-library/react": "^16.2.0", "@types/react": "^19.1.2", diff --git a/package.json b/package.json index 77bd0de2..874fa56b 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,10 @@ { "path": "packages/devtools/dist/esm/index.js", "limit": "30 KB" + }, + { + "path": "packages/event-bus-client/dist/esm/plugin.js", + "limit": "1 KB" } ], "devDependencies": { diff --git a/packages/event-bus-client/package.json b/packages/event-bus-client/package.json index 955ea074..c2447a59 100644 --- a/packages/event-bus-client/package.json +++ b/packages/event-bus-client/package.json @@ -32,6 +32,16 @@ "default": "./dist/cjs/index.cjs" } }, + "./production": { + "import": { + "types": "./dist/esm/production.d.ts", + "default": "./dist/esm/production.js" + }, + "require": { + "types": "./dist/cjs/production.d.cts", + "default": "./dist/cjs/production.cjs" + } + }, "./package.json": "./package.json" }, "sideEffects": false, diff --git a/packages/event-bus-client/src/index.ts b/packages/event-bus-client/src/index.ts index 6b3402a0..64c65978 100644 --- a/packages/event-bus-client/src/index.ts +++ b/packages/event-bus-client/src/index.ts @@ -1 +1,24 @@ -export { EventClient } from './plugin' +import * as Client from './plugin' + +class MockClass { + on(_: string, __: (...args: Array) => void) { + // No-op in production + } + onAll(_: (...args: Array) => void) { + // No-op in production + } + onAllPluginEvents(_: (...args: Array) => void) { + // No-op in production + } + emit(_: string, ...__: Array) { + // No-op in production + } + getPluginId() { + // No-op in production + } +} + +export const EventClient: (typeof Client)['EventClient'] = + process.env.NODE_ENV !== 'development' && process.env.NODE_ENV !== 'test' + ? (MockClass as any) + : Client.EventClient diff --git a/packages/event-bus-client/src/production.ts b/packages/event-bus-client/src/production.ts new file mode 100644 index 00000000..6b3402a0 --- /dev/null +++ b/packages/event-bus-client/src/production.ts @@ -0,0 +1 @@ +export { EventClient } from './plugin' diff --git a/packages/event-bus-client/vite.config.ts b/packages/event-bus-client/vite.config.ts index 79dae7cd..60d2a34a 100644 --- a/packages/event-bus-client/vite.config.ts +++ b/packages/event-bus-client/vite.config.ts @@ -17,7 +17,7 @@ const config = defineConfig({ export default mergeConfig( config, tanstackViteConfig({ - entry: ['./src/index.ts'], + entry: ['./src/index.ts', './src/production.ts'], srcDir: './src', }), ) diff --git a/packages/react-devtools/package.json b/packages/react-devtools/package.json index d9f3a2ff..3118cccd 100644 --- a/packages/react-devtools/package.json +++ b/packages/react-devtools/package.json @@ -33,6 +33,16 @@ "default": "./dist/cjs/index.cjs" } }, + "./production": { + "import": { + "types": "./dist/esm/production.d.ts", + "default": "./dist/esm/production.js" + }, + "require": { + "types": "./dist/cjs/production.d.cts", + "default": "./dist/cjs/production.cjs" + } + }, "./package.json": "./package.json" }, "sideEffects": false, diff --git a/packages/react-devtools/src/devtools.tsx b/packages/react-devtools/src/devtools.tsx index 9218e35f..b60dff4a 100644 --- a/packages/react-devtools/src/devtools.tsx +++ b/packages/react-devtools/src/devtools.tsx @@ -5,7 +5,7 @@ import { TanStackDevtoolsCore, } from '@tanstack/devtools' import { createPortal } from 'react-dom' -import type { JSX } from 'react' +import type { JSX, ReactElement } from 'react' import type { ClientEventBusConfig, TanStackDevtoolsConfig, @@ -101,7 +101,7 @@ export const TanStackDevtools = ({ plugins, config, eventBusConfig, -}: TanStackDevtoolsReactInit) => { +}: TanStackDevtoolsReactInit): ReactElement | null => { const devToolRef = useRef(null) const [pluginContainer, setPluginContainer] = useState( null, diff --git a/packages/react-devtools/src/index.ts b/packages/react-devtools/src/index.ts index e23e97f8..3f95d65e 100644 --- a/packages/react-devtools/src/index.ts +++ b/packages/react-devtools/src/index.ts @@ -1,8 +1,15 @@ -// re-export everything from the core devtools package -export * from '@tanstack/devtools' -/** - * Export every hook individually - DON'T export from barrel files - */ +'use client' -export * from './devtools' -export type { TanStackDevtoolsReactPlugin } from './devtools' +import * as Devtools from './devtools' + +export const TanStackDevtools: (typeof Devtools)['TanStackDevtools'] = + process.env.NODE_ENV !== 'development' + ? function () { + return null + } + : Devtools.TanStackDevtools + +export type { + TanStackDevtoolsReactPlugin, + TanStackDevtoolsReactInit, +} from './devtools' diff --git a/packages/react-devtools/src/production.ts b/packages/react-devtools/src/production.ts new file mode 100644 index 00000000..ca1f4fb5 --- /dev/null +++ b/packages/react-devtools/src/production.ts @@ -0,0 +1,10 @@ +'use client' + +import * as Devtools from './devtools' + +export const TanStackDevtools = Devtools.TanStackDevtools + +export type { + TanStackDevtoolsReactPlugin, + TanStackDevtoolsReactInit, +} from './devtools' diff --git a/packages/react-devtools/vite.config.ts b/packages/react-devtools/vite.config.ts index 391ebb38..8da83633 100644 --- a/packages/react-devtools/vite.config.ts +++ b/packages/react-devtools/vite.config.ts @@ -1,7 +1,8 @@ -import { defineConfig, mergeConfig, Plugin } from 'vitest/config' +import { defineConfig, mergeConfig } from 'vitest/config' import { tanstackViteConfig } from '@tanstack/config/vite' import react from '@vitejs/plugin-react' import packageJson from './package.json' +import type { Plugin } from 'vitest/config' const config = defineConfig({ plugins: [react() as any satisfies Plugin], @@ -18,7 +19,7 @@ const config = defineConfig({ export default mergeConfig( config, tanstackViteConfig({ - entry: ['./src/index.ts'], + entry: ['./src/index.ts', './src/production.ts'], srcDir: './src', }), ) diff --git a/packages/solid-devtools/package.json b/packages/solid-devtools/package.json index e3014c14..94371446 100644 --- a/packages/solid-devtools/package.json +++ b/packages/solid-devtools/package.json @@ -33,6 +33,16 @@ "default": "./dist/cjs/index.cjs" } }, + "./production": { + "import": { + "types": "./dist/esm/production.d.ts", + "default": "./dist/esm/production.js" + }, + "require": { + "types": "./dist/cjs/production.d.cts", + "default": "./dist/cjs/production.cjs" + } + }, "./package.json": "./package.json" }, "sideEffects": false, diff --git a/packages/solid-devtools/src/index.ts b/packages/solid-devtools/src/index.ts index 1f595f69..c6c88474 100644 --- a/packages/solid-devtools/src/index.ts +++ b/packages/solid-devtools/src/index.ts @@ -1,8 +1,10 @@ -// re-export everything from the core devtools package -export * from '@tanstack/devtools' -/** - * Export every hook individually - DON'T export from barrel files - */ +import { isDev } from 'solid-js/web' +import * as Devtools from './devtools' + +export const TanStackDevtools: (typeof Devtools)['TanStackDevtools'] = isDev + ? Devtools.TanStackDevtools + : function () { + return null + } -export { TanStackDevtools } from './devtools' export type { TanStackDevtoolsSolidPlugin } from './core' diff --git a/packages/solid-devtools/src/production.ts b/packages/solid-devtools/src/production.ts new file mode 100644 index 00000000..0d4d4c06 --- /dev/null +++ b/packages/solid-devtools/src/production.ts @@ -0,0 +1,6 @@ +import * as Devtools from './devtools' + +export const TanStackDevtools: (typeof Devtools)['TanStackDevtools'] = + Devtools.TanStackDevtools + +export type { TanStackDevtoolsSolidPlugin } from './core' diff --git a/packages/solid-devtools/vite.config.ts b/packages/solid-devtools/vite.config.ts index 49a9edb7..f6a7cb3c 100644 --- a/packages/solid-devtools/vite.config.ts +++ b/packages/solid-devtools/vite.config.ts @@ -2,7 +2,7 @@ import { defineConfig, mergeConfig } from 'vitest/config' import { tanstackViteConfig } from '@tanstack/config/vite' import solid from 'vite-plugin-solid' import packageJson from './package.json' -import { Plugin } from 'vite' +import type { Plugin } from 'vite' const config = defineConfig({ plugins: [solid() as any satisfies Plugin], @@ -19,7 +19,7 @@ const config = defineConfig({ export default mergeConfig( config, tanstackViteConfig({ - entry: ['./src/index.ts'], + entry: ['./src/index.ts', './src/production.ts'], srcDir: './src', }), ) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6899b8e4..6d39a140 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -206,9 +206,6 @@ importers: specifier: ^4.0.14 version: 4.0.14 devDependencies: - '@tanstack/devtools': - specifier: ^0.4.0 - version: link:../../../packages/devtools '@testing-library/dom': specifier: ^10.4.0 version: 10.4.1 @@ -240,6 +237,8 @@ importers: specifier: ^4.2.4 version: 4.2.4 + examples/react/start/generated/prisma: {} + examples/react/time-travel: dependencies: '@tanstack/devtools-event-client':