diff --git a/.changeset/nine-ravens-push.md b/.changeset/nine-ravens-push.md new file mode 100644 index 00000000..9a8dd5fb --- /dev/null +++ b/.changeset/nine-ravens-push.md @@ -0,0 +1,5 @@ +--- +'@tanstack/devtools-vite': patch +--- + +fix issue where hosting providers would include devtools in production diff --git a/packages/devtools-vite/src/plugin.ts b/packages/devtools-vite/src/plugin.ts index 93248fef..665ee83c 100644 --- a/packages/devtools-vite/src/plugin.ts +++ b/packages/devtools-vite/src/plugin.ts @@ -178,18 +178,18 @@ export const devtools = (args?: TanStackDevtoolsViteConfig): Array => { }, { name: '@tanstack/devtools:remove-devtools-on-build', - apply(_, { command }) { - return command === 'build' && removeDevtoolsOnBuild + apply(config, { command }) { + // Check both command and mode to support various hosting providers + // Some providers (Cloudflare, Netlify, Heroku) might not use 'build' command + // but will always set mode to 'production' for production builds + return ( + (command !== 'serve' || config.mode === 'production') && + removeDevtoolsOnBuild + ) }, enforce: 'pre', transform(code, id) { - if ( - id.includes('node_modules') || - id.includes('?raw') || - id.includes('dist') || - id.includes('build') - ) - return + if (id.includes('node_modules') || id.includes('?raw')) return const transform = removeDevtools(code, id) if (!transform) return if (logging) {