Registry / devops / common-shakeify

common-shakeify

JSON →
library1.1.2jsnpmunverified

Browserify tree-shaking plugin using the CommonJS tree shaker common-shake. Current stable version is 1.1.2, with no recent updates. It comments out unused CommonJS exports from modules during bundling, allowing a subsequent minifier to eliminate dead code. Key differentiator: unlike ES module tree-shakers, it supports CommonJS modules, which are prevalent in older or Node-based projects. Works only with browserify, not standalone.

npm install common-shakeify
INSTALL
IMPORT
SIG · COMMON-SHAKEIFY
C
common-shakeify
devopsjavascriptv1.1.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

default
var commonShake = require('common-shakeify')
The package is CJS-only; there is no default ESM export. Use require().
plugin usage
b.plugin(commonShake, { verbose: true })
b.transform(commonShake, {})
common-shakeify is a browserify plugin, not a transform. Must be added via .plugin(), not .transform().
CLI usage
browserify -p common-shakeify app.js > bundle.js
browserify -t common-shakeify app.js > bundle.js
Use -p (plugin) flag, not -t (transform).

Setup common-shakeify as a browserify plugin to tree-shake CommonJS modules and then minify the output.

var browserify = require('browserify'); var commonShake = require('common-shakeify'); var fs = require('fs'); var b = browserify({ entries: ['./app.js'] }); b.plugin(commonShake, { verbose: true }); b.bundle().pipe(fs.createWriteStream('bundle.js')); // then minify with uglify-js: uglifyjs bundle.js --compress > bundle.min.js
Debug
Known issues
gotchaMinifier transforms like uglifyify do NOT remove the commented-out exports because transforms run before common-shakeify.
fix
Use a minifier on the final bundle (e.g., uglify-js) after browserify finishes, not as a transform.
affects: >=1.0.0
gotchaDynamic require() calls cause the plugin to bail on tree-shaking globally.
fix
Avoid dynamic requires (e.g., require(variable)) or use the onGlobalBailout callback to detect and handle.
affects: >=1.0.0
gotchaThe verbose flag only works when no custom handlers are passed; if using onExportDelete etc., you must handle printing manually.
fix
Add your own console.log statements inside custom handlers if you want verbose output.
affects: >=1.0.0
gotchaECMAScript version parsing defaults to 10 (never updated for newer syntax like optional chaining).
fix
Set the ecmaVersion option to a higher number (e.g., 2020) if your code uses modern JS features.
affects: >=1.0.0
gotchamodule.exports assignments cause the module to be marked as deoptimized (bailed out), preventing tree-shaking for that module.
fix
Use exports.* = ... instead of module.exports = ... where possible.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: commonShake is not a function
Using the package as a transform with .transform() instead of .plugin()
fix
Replace b.transform(commonShake) with b.plugin(commonShake)
Error: Could not find plugin "common-shakeify"
Missing installation or wrong package name in CLI -p flag
fix
Run `npm install --save-dev common-shakeify` and ensure the CLI flag is `-p common-shakeify`
common-shake: bailed out: `module.exports` assignment
The module uses module.exports = ... which disables tree-shaking for that file
fix
Refactor to use exports.name = ... or use the onModuleBailout callback to handle
Unexpected token: punc (.)
Acorn parser cannot handle modern JavaScript syntax (e.g., optional chaining, nullish coalescing) with default ecmaVersion=10
fix
Set ecmaVersion option to e.g., 2020: `b.plugin(commonShake, { ecmaVersion: 2020 })`
Upgrade
Version history
1.1.2latest on npm
Audit
Dependencies
common-shakerequiredCore tree-shaking logic for CommonJS modules
Agent activity
5 hits · last 30 days
node
4
Bingbot
1
Resources
common-shakeify — npm install common-shakeify · libregistry