vite-plugin-stripper

raw JSON →
0.10.1 verified Mon Apr 27 auth: no javascript

A Vite plugin that strips out specified functions from your browser bundle, removing debug or development-only code in production. Current stable version is 0.10.1, released as part of the KitQL monorepo. It uses oxc (since v0.10.0) for fast parsing instead of babel/recast. Works with Vite 5, 6, 7, or 8. Key differentiator: lightweight, tree-shakable, and focused on stripping function calls, not entire files. Requires Node ^16.14 || >=18.

error require() of ES Module /path/to/node_modules/vite-plugin-stripper/dist/index.mjs not supported
cause Using CommonJS require() to import an ESM-only package.
fix
Change to import statement or use dynamic import().
error ERR_MODULE_NOT_FOUND: Cannot find package 'vite'
cause Missing peer dependency 'vite'.
fix
Install vite: npm install -D vite
error TypeError: vitePluginStripper is not a function
cause Using named import instead of default import.
fix
Use import vitePluginStripper from 'vite-plugin-stripper' (no curly braces).
breaking Since v0.10.0, the option `log_on_throw_is_not_a_new_class` has been removed.
fix Remove usage of `log_on_throw_is_not_a_new_class`. If needed, open a GitHub issue to request re-implementation.
breaking Parsing engine changed from babel/recast to oxc in v0.10.0, which may produce different AST results and potentially different stripping behavior.
fix Test your build after upgrading; verify that targeted functions are still stripped correctly.
gotcha The plugin is only active in production builds by default. It does not strip functions in dev mode.
fix To test in dev, set `apply: 'build'` or use `apply: (config, { command }) => command === 'build'` in plugin options.
gotcha If using Vite 5, ensure vite-plugin-stripper version is at least 0.10.0 (which supports Vite 5). Older versions may not work.
fix Upgrade to vite-plugin-stripper@^0.10.0.
deprecated Node 16 support is deprecated as of v0.10.0? The engine field allows ^16.14, but Node 16 is end-of-life.
fix Use Node 18 or later for security and performance.
npm install vite-plugin-stripper
yarn add vite-plugin-stripper
pnpm add vite-plugin-stripper

Configures vite-plugin-stripper to remove console.log, debug, and myCustomDebug from source files in production build.

// vite.config.ts
import { defineConfig } from 'vite'
import vitePluginStripper from 'vite-plugin-stripper'

export default defineConfig({
  plugins: [
    vitePluginStripper({
      strip: ['console.log', 'debug', 'myCustomDebug'],
      include: ['src/**/*.ts'],
      exclude: ['node_modules/**'],
      sourcemap: true
    })
  ]
})