diff --git a/.changeset/solid-svelte-query-devtools-production-entry.md b/.changeset/solid-svelte-query-devtools-production-entry.md new file mode 100644 index 00000000000..7e8afa3d0ab --- /dev/null +++ b/.changeset/solid-svelte-query-devtools-production-entry.md @@ -0,0 +1,6 @@ +--- +'@tanstack/solid-query-devtools': minor +'@tanstack/svelte-query-devtools': minor +--- + +feat({solid,svelte}-query-devtools): add './production' entry to lazy load the devtools in production builds diff --git a/docs/framework/solid/devtools.md b/docs/framework/solid/devtools.md index 6f79c192234..59419e65b09 100644 --- a/docs/framework/solid/devtools.md +++ b/docs/framework/solid/devtools.md @@ -143,3 +143,52 @@ function App() { - `theme?: "light" | "dark" | "system"` - Defaults to the theme selected in the devtools Settings menu, or `system` if none is selected. - Set this to change the theme of the devtools panel. This overrides the theme selected in the Settings menu. + +## Devtools in production + +Devtools are excluded in production builds. However, it might be desirable to lazy load the devtools in production: + +```tsx +import { createSignal, lazy, onMount, Show, Suspense } from 'solid-js' +import { QueryClient, QueryClientProvider } from '@tanstack/solid-query' +import { SolidQueryDevtools } from '@tanstack/solid-query-devtools' +import { Example } from './Example' + +const queryClient = new QueryClient() + +const SolidQueryDevtoolsProduction = lazy(() => + import('@tanstack/solid-query-devtools/production').then((d) => ({ + default: d.SolidQueryDevtools, + })), +) + +function App() { + const [showDevtools, setShowDevtools] = createSignal(false) + + onMount(() => { + Object.assign(window, { + toggleDevtools: () => setShowDevtools((old) => !old), + }) + }) + + return ( + + + + + + + + + + ) +} + +export default App +``` + +With this, calling `window.toggleDevtools()` will download the devtools bundle and show them. + +`@tanstack/solid-query-devtools/production` also exports `SolidQueryDevtoolsPanel` for Embedded Mode. + +For TypeScript, you would need to set `moduleResolution` to `'bundler'`, `'node16'`, or `'nodenext'` in your tsconfig. diff --git a/docs/framework/svelte/devtools.md b/docs/framework/svelte/devtools.md index 5ab7a518ce4..fcbcbf429a1 100644 --- a/docs/framework/svelte/devtools.md +++ b/docs/framework/svelte/devtools.md @@ -41,6 +41,8 @@ You can import the devtools like this: import { SvelteQueryDevtools } from '@tanstack/svelte-query-devtools' ``` +By default, Svelte Query Devtools are only rendered in development, using `DEV` from `esm-env`. In production, the devtools component renders nothing. + ## Floating Mode Floating Mode will mount the devtools as a fixed, floating element in your app and provide a toggle in the corner of the screen to show and hide the devtools. This toggle state will be stored and remembered in localStorage across reloads. @@ -85,3 +87,40 @@ Place the following code as high in your Svelte app as you can. The closer it is - `theme?: Theme` - Defaults to the theme selected in the devtools Settings menu, or `system` if none is selected. - Set this to change the theme of the devtools panel. This overrides the theme selected in the Settings menu. + +## Devtools in production + +Devtools are excluded in production builds. However, it might be desirable to lazy load the devtools in production: + +```svelte + + + + + + {#if showDevtools} + {#await import('@tanstack/svelte-query-devtools/production') then { SvelteQueryDevtools: SvelteQueryDevtoolsProduction }} + + {/await} + {/if} + +``` + +With this, calling `window.toggleDevtools()` will download the devtools bundle and show them. + +For TypeScript, you would need to set `moduleResolution` to `'bundler'`, `'node16'`, or `'nodenext'` in your tsconfig. diff --git a/packages/solid-query-devtools/.attw.json b/packages/solid-query-devtools/.attw.json new file mode 100644 index 00000000000..de5330c3cd2 --- /dev/null +++ b/packages/solid-query-devtools/.attw.json @@ -0,0 +1,3 @@ +{ + "ignoreRules": ["no-resolution"] +} diff --git a/packages/solid-query-devtools/package.json b/packages/solid-query-devtools/package.json index 2c57166cb4e..53c1d89c843 100644 --- a/packages/solid-query-devtools/package.json +++ b/packages/solid-query-devtools/package.json @@ -37,23 +37,35 @@ "types": "./build/index.d.ts", "browser": {}, "exports": { - "@tanstack/custom-condition": "./src/index.tsx", - "solid": { - "development": "./build/dev.jsx", - "import": "./build/index.jsx" - }, - "development": { + ".": { + "@tanstack/custom-condition": "./src/index.tsx", + "solid": { + "development": "./build/dev.jsx", + "import": "./build/index.jsx" + }, + "development": { + "import": { + "types": "./build/index.d.ts", + "default": "./build/dev.js" + }, + "require": "./build/dev.cjs" + }, "import": { "types": "./build/index.d.ts", - "default": "./build/dev.js" + "default": "./build/index.js" }, - "require": "./build/dev.cjs" + "require": "./build/index.cjs" }, - "import": { - "types": "./build/index.d.ts", - "default": "./build/index.js" + "./production": { + "@tanstack/custom-condition": "./src/production.tsx", + "solid": "./build/production.jsx", + "import": { + "types": "./build/production.d.ts", + "default": "./build/production.js" + }, + "require": "./build/production.cjs" }, - "require": "./build/index.cjs" + "./package.json": "./package.json" }, "sideEffects": false, "files": [ diff --git a/packages/solid-query-devtools/src/production.tsx b/packages/solid-query-devtools/src/production.tsx new file mode 100644 index 00000000000..3692bfbb77a --- /dev/null +++ b/packages/solid-query-devtools/src/production.tsx @@ -0,0 +1,7 @@ +import SolidQueryDevtoolsComp from './devtools' +import SolidQueryDevtoolsCompPanel from './devtoolsPanel' + +export const SolidQueryDevtools = SolidQueryDevtoolsComp +export const SolidQueryDevtoolsPanel = SolidQueryDevtoolsCompPanel + +export type { DevtoolsPanelOptions } from './devtoolsPanel' diff --git a/packages/solid-query-devtools/tsdown.config.ts b/packages/solid-query-devtools/tsdown.config.ts index c58d4ae1321..6a764e8bc5c 100644 --- a/packages/solid-query-devtools/tsdown.config.ts +++ b/packages/solid-query-devtools/tsdown.config.ts @@ -55,8 +55,15 @@ const jsxConfig = ( }) export default defineConfig([ - compiledConfig({ index: 'src/index.tsx' }, false, true), - jsxConfig({ index: 'src/index.tsx' }, false), + compiledConfig( + { index: 'src/index.tsx', production: 'src/production.tsx' }, + false, + true, + ), + jsxConfig( + { index: 'src/index.tsx', production: 'src/production.tsx' }, + false, + ), compiledConfig({ dev: 'src/index.tsx' }, true, false), jsxConfig({ dev: 'src/index.tsx' }, true), ]) diff --git a/packages/svelte-query-devtools/.attw.json b/packages/svelte-query-devtools/.attw.json index d4b76dfa757..864f618c225 100644 --- a/packages/svelte-query-devtools/.attw.json +++ b/packages/svelte-query-devtools/.attw.json @@ -1,3 +1,7 @@ { - "ignoreRules": ["cjs-resolves-to-esm", "internal-resolution-error"] + "ignoreRules": [ + "cjs-resolves-to-esm", + "internal-resolution-error", + "no-resolution" + ] } diff --git a/packages/svelte-query-devtools/package.json b/packages/svelte-query-devtools/package.json index 7e8b1e2f8d7..97127d3a012 100644 --- a/packages/svelte-query-devtools/package.json +++ b/packages/svelte-query-devtools/package.json @@ -45,6 +45,12 @@ "svelte": "./dist/index.js", "import": "./dist/index.js" }, + "./production": { + "@tanstack/custom-condition": "./src/production.ts", + "types": "./dist/production.d.ts", + "svelte": "./dist/production.js", + "import": "./dist/production.js" + }, "./package.json": "./package.json" }, "files": [ diff --git a/packages/svelte-query-devtools/src/Devtools.svelte b/packages/svelte-query-devtools/src/SvelteQueryDevtools.svelte similarity index 98% rename from packages/svelte-query-devtools/src/Devtools.svelte rename to packages/svelte-query-devtools/src/SvelteQueryDevtools.svelte index 80133231ad2..6f7817825a5 100644 --- a/packages/svelte-query-devtools/src/Devtools.svelte +++ b/packages/svelte-query-devtools/src/SvelteQueryDevtools.svelte @@ -1,6 +1,6 @@