babel-plugin-strip-function-call
raw JSON → 1.0.2 verified Sat Apr 25 auth: no javascript
A Babel plugin that removes specific function calls (e.g., console.log) from your production code. Version 1.0.2 is the latest stable release, updated via bug fixes only. It is similar to webpack's strip-loader but tailored for Babel environments. The plugin is minimal, allowing you to specify an array of function call patterns to strip. It does not support computed property patterns (e.g., console["log"]) by design. Best paired with a process.env.NODE_ENV check for conditional stripping in production builds. Active development is low; the plugin is maintained but rarely updated.
Common errors
error Cannot find module 'babel-plugin-strip-function-call' ↓
cause The plugin is not installed or npm install failed.
fix
Run 'npm install babel-plugin-strip-function-call --save-dev'.
error Error: [BABEL] unknown: Plugin "strip-function-call" threw: Error: Cannot read property 'split' of undefined ↓
cause The plugin is configured but the 'strip' option is missing or undefined.
fix
Ensure the plugin configuration includes a 'strip' array: e.g., ["strip-function-call", { "strip": ["console.log"] }]
error console.log still appears after build ↓
cause The plugin may not be applied due to missing env configuration or incorrect plugin name.
fix
Check that NODE_ENV is set to 'production' and that the plugin name is 'strip-function-call' inside Babel config.
Warnings
gotcha Does not strip computed property patterns like console["log"](...) by design. ↓
fix Use a different plugin or custom Babel visitor if you need to strip computed calls.
gotcha The plugin name in Babel config must be 'strip-function-call', not 'babel-plugin-strip-function-call'. ↓
fix Use 'strip-function-call' as the plugin name inside your .babelrc or babel.config.js.
gotcha If you do not specify a 'strip' array, the plugin will do nothing silently. ↓
fix Always provide a 'strip' option with an array of function call strings. Example: { "strip": ["console.log"] }
gotcha The plugin is not a preset; it must be listed under 'plugins', not 'presets'. ↓
fix Place it in the 'plugins' array of your Babel config.
Install
npm install babel-plugin-strip-function-call yarn add babel-plugin-strip-function-call pnpm add babel-plugin-strip-function-call Imports
- strip-function-call wrong
import strip from 'babel-plugin-strip-function-call';correctmodule.exports = require('babel-plugin-strip-function-call'); - Babel plugin configuration wrong
{ "plugins": [ "strip-function-call" ] }correct{ "plugins": [ ["strip-function-call", { "strip": ["console.log"] }] ] } - Env-specific usage wrong
{ "plugins": [ ["strip-function-call", { "strip": ["console.log"] }] ] }correct{ "env": { "production": { "plugins": [ ["strip-function-call", { "strip": ["console.log"] }] ] } } }
Quickstart
// .babelrc example:
{
"env": {
"production": {
"plugins": [
["strip-function-call", { "strip": ["console.log"] }]
]
}
}
}
// Input:
console.log('Hello World');
// Output (production):
// (empty - line removed)
// Note: The plugin only removes exact matches, not computed member expressions like console["log"]().