Registry / devops / vite-plugin-remove-console

vite-plugin-remove-console

JSON →
library2.2.0jsnpmunverified

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.

npm install vite-plugin-remove-console
INSTALL
IMPORT
SIG · VITE-PLUGIN-REMOVE
V
vite-plugin-remove-console
devopsjavascriptv2.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

removeConsole
import removeConsole from 'vite-plugin-remove-console'
import { removeConsole } from 'vite-plugin-remove-console'
Default export. Named export does not exist.
defineConfig
import { defineConfig } from 'vite'
import defineConfig from 'vite'
Common pattern used together with the plugin; shown in quickstart.
type RemoveConsoleOptions
import type { RemoveConsoleOptions } from 'vite-plugin-remove-console'
import { RemoveConsoleOptions } from 'vite-plugin-remove-console'
Type is only exported for TypeScript; do not use as value.

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.

// vite.config.ts import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' import removeConsole from 'vite-plugin-remove-console' export default defineConfig({ plugins: [ vue(), removeConsole({ includes: ['log', 'warn', 'error'], externalValue: ['keep this'], external: ['src/no-remove.js'] }) ] })
Debug
Known issues
gotchaThe plugin removes console statements only in production builds. Does not affect development.
fix
Use process.env.NODE_ENV check if you need conditional removal in dev.
affects: >=1.0.0
breakingv2.0.0 changed the default behavior: previously removed all console statements; now only removes console.log if no `includes` option provided.
fix
Explicitly pass includes: ['log', 'warn', 'error', 'info', 'debug'] to restore old behavior.
affects: >=2.0.0 <2.0.0
gotchaUsing `custom` option completely overrides `includes` option. They are not additive.
fix
Do not combine `custom` with `includes`; choose one approach.
affects: >=2.2.0
deprecatedOption `external` can cause issues on Windows due to path separator backslashes.
fix
Use forward slashes in paths, or upgrade to >=1.0.4 which fixes path translation.
affects: <1.0.4
gotchaThe `externalValue` option matches against the string argument of the console call. Works only for simple string literals, not expressions.
fix
Use simple string literals like 'keep this' inside console.log('keep this').
affects: >=2.1.0
Errors
Common errors & fixes
Cannot find module 'vite-plugin-remove-console' or its corresponding type declarations.
Missing installation or tsconfig not resolving types.
fix
Run npm install vite-plugin-remove-console -D and ensure tsconfig.json includes 'node_modules/@types' or use 'moduleResolution': 'node'.
TypeError: removeConsole is not a function
Importing as named export instead of default export.
fix
Use: import removeConsole from 'vite-plugin-remove-console'
The 'custom' option is not supported in version 1.x.
Using custom option with older version of the plugin.
fix
Upgrade to >=2.2.0: npm install vite-plugin-remove-console@2.2.0 -D
Error: Plugin 'vite-plugin-remove-console' not recognized. Ensure it's in the plugins array and imported correctly.
Plugin not added to plugins array or imported incorrectly.
fix
Add removeConsole() to plugins array in vite.config.ts: plugins: [vue(), removeConsole()]
Upgrade
Version history
2.2.0latest on npm
Audit
Dependencies
viterequiredpeer dependency - required to use any Vite plugin
Agent activity
3 hits · last 30 days
node
2
Resources
vite-plugin-remove-console — npm install vite-plugin-remove-console · libregistry