{"id":22809,"library":"vite-plugin-remove-console","title":"vite-plugin-remove-console","description":"A Vite plugin that removes specified console statements in production builds. Current stable version is 2.2.0 (released 2023-12-04). Active development with regular releases. Key differentiators: supports custom removal statements via `custom` option, can retain specific console values via `externalValue`, and can exclude certain files via `external`. Works with .js, .ts, .jsx, .tsx, .vue, .svelte files. Comparison alternatives: unplugin-remove-console may be more framework-agnostic, but this plugin is Vite-specific and simple to configure.","status":"active","version":"2.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/xiaoxian521/vite-plugin-remove-console","tags":["javascript","vite","console","remove-console","typescript"],"install":[{"cmd":"npm install vite-plugin-remove-console","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-remove-console","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-remove-console","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency - required to use any Vite plugin","package":"vite","optional":false}],"imports":[{"note":"Default export. Named export does not exist.","wrong":"import { removeConsole } from 'vite-plugin-remove-console'","symbol":"removeConsole","correct":"import removeConsole from 'vite-plugin-remove-console'"},{"note":"Common pattern used together with the plugin; shown in quickstart.","wrong":"import defineConfig from 'vite'","symbol":"defineConfig","correct":"import { defineConfig } from 'vite'"},{"note":"Type is only exported for TypeScript; do not use as value.","wrong":"import { RemoveConsoleOptions } from 'vite-plugin-remove-console'","symbol":"type RemoveConsoleOptions","correct":"import type { RemoveConsoleOptions } from 'vite-plugin-remove-console'"}],"quickstart":{"code":"// vite.config.ts\nimport { defineConfig } from 'vite'\nimport vue from '@vitejs/plugin-vue'\nimport removeConsole from 'vite-plugin-remove-console'\n\nexport default defineConfig({\n  plugins: [\n    vue(),\n    removeConsole({\n      includes: ['log', 'warn', 'error'],\n      externalValue: ['keep this'],\n      external: ['src/no-remove.js']\n    })\n  ]\n})","lang":"typescript","description":"Typical Vite configuration using vite-plugin-remove-console to remove console.log, console.warn, console.error in production, while keeping statements with specific values and excluding a file."},"warnings":[{"fix":"Use process.env.NODE_ENV check if you need conditional removal in dev.","message":"The plugin removes console statements only in production builds. Does not affect development.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Explicitly pass includes: ['log', 'warn', 'error', 'info', 'debug'] to restore old behavior.","message":"v2.0.0 changed the default behavior: previously removed all console statements; now only removes console.log if no `includes` option provided.","severity":"breaking","affected_versions":">=2.0.0 <2.0.0"},{"fix":"Do not combine `custom` with `includes`; choose one approach.","message":"Using `custom` option completely overrides `includes` option. They are not additive.","severity":"gotcha","affected_versions":">=2.2.0"},{"fix":"Use forward slashes in paths, or upgrade to >=1.0.4 which fixes path translation.","message":"Option `external` can cause issues on Windows due to path separator backslashes.","severity":"deprecated","affected_versions":"<1.0.4"},{"fix":"Use simple string literals like 'keep this' inside console.log('keep this').","message":"The `externalValue` option matches against the string argument of the console call. Works only for simple string literals, not expressions.","severity":"gotcha","affected_versions":">=2.1.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Run npm install vite-plugin-remove-console -D and ensure tsconfig.json includes 'node_modules/@types' or use 'moduleResolution': 'node'.","cause":"Missing installation or tsconfig not resolving types.","error":"Cannot find module 'vite-plugin-remove-console' or its corresponding type declarations."},{"fix":"Use: import removeConsole from 'vite-plugin-remove-console'","cause":"Importing as named export instead of default export.","error":"TypeError: removeConsole is not a function"},{"fix":"Upgrade to >=2.2.0: npm install vite-plugin-remove-console@2.2.0 -D","cause":"Using custom option with older version of the plugin.","error":"The 'custom' option is not supported in version 1.x."},{"fix":"Add removeConsole() to plugins array in vite.config.ts: plugins: [vue(), removeConsole()]","cause":"Plugin not added to plugins array or imported incorrectly.","error":"Error: Plugin 'vite-plugin-remove-console' not recognized. Ensure it's in the plugins array and imported correctly."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}