Registry / devops / webpack-common-shake

webpack-common-shake

JSON →
library2.1.0jsnpmunverified

Webpack plugin for tree-shaking CommonJS modules. Version 2.1.0 is the latest stable release, published in 2019. It removes unused assignments to exports properties, leaving dead code elimination to UglifyJS. Unlike ES module tree-shaking, this targets CommonJS exports. Works with Webpack 4+; for Webpack 3 use version 1.x. Provides options for warnings and bailout callbacks. Notable limitations: dynamic exports, dynamic require, and certain re-assignments cause bailouts.

npm install webpack-common-shake
INSTALL
IMPORT
SIG · WEBPACK-COMMON-SHA
W
webpack-common-shake
devopsjavascriptv2.1.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 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

ShakePlugin
const { ShakePlugin } = require('webpack-common-shake');
import { Plugin } from 'webpack-common-shake';
CommonJS module; does not support ESM imports. Use require or dynamic import().
Plugin
const ShakePlugin = require('webpack-common-shake').Plugin;
import ShakePlugin from 'webpack-common-shake';
Named export, not default.
ShakePlugin
import { ShakePlugin } from 'webpack-common-shake';
const { ShakePlugin } = require('webpack-common-shake');
Works in ESM context, but package is CJS; dynamic import also possible.

Basic Webpack 4+ configuration with ShakePlugin, including optional callbacks for export deletion and bailouts.

const ShakePlugin = require('webpack-common-shake').Plugin; module.exports = { entry: './src/index.js', output: { path: __dirname + '/dist', filename: 'bundle.js' }, plugins: [ new ShakePlugin({ warnings: { global: true, module: false }, onExportDelete: (resource, property) => { console.log(`Deleted ${property} from ${resource}`); }, onModuleBailout: (module, bailouts) => { console.warn(`Bailout for ${module}: ${bailouts.join(', ')}`); }, onGlobalBailout: (bailouts) => { console.warn(`Global bailout: ${bailouts.join(', ')}`); } }) ] };
Debug
Known issues
breakingPlugin must be used with Webpack 4+; Webpack 3 requires version 1.x.
fix
Use webpack-common-shake@1.x with Webpack 3, or upgrade to Webpack 4+.
affects: >=2.0.0
gotchaDynamic exports like exports[Math.random()] cause module bailout; tree-shaking disabled for that module.
fix
Avoid dynamic property access on exports. Use static export assignments.
affects: >=0
gotchaOverriding required module variable (e.g., var a = require('./a'); a = require('./b')) causes bailout.
fix
Do not reassign variables that hold required modules.
affects: >=0
gotchaUsing require in non-standard ways (e.g., console.log(require('./lib'))) may cause bailout.
fix
Assign require result to a variable before using.
affects: >=0
gotchaDynamic import like require('./lib')[Math.random()] causes bailout.
fix
Use static import paths and access properties directly.
affects: >=0
gotchaDynamic require (e.g., require(Math.random())) causes global bailout; plugin disabled entirely.
fix
Avoid dynamic require expressions.
affects: >=0
Errors
Common errors & fixes
Cannot find module 'webpack-common-shake'
Package not installed or wrong import path.
fix
npm install webpack-common-shake --save-dev
ShakePlugin is not a constructor
Incorrect import: using default import instead of named export.
fix
const ShakePlugin = require('webpack-common-shake').Plugin;
Module parse failed: Unexpected token (1:0)
Webpack version incompatible (<4).
fix
Upgrade to Webpack 4+ or use webpack-common-shake@1.x.
Bailout: dynamic require detected
Dynamic require call in code.
fix
Remove dynamic require or use onGlobalBailout to handle.
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies
common-shakerequiredCore tree-shaking algorithm for CommonJS modules
webpackrequiredPeer dependency: Webpack 4+ required
Agent activity
6 hits · last 30 days
node
6
Resources