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-shakeVerified import paths — ran on the pinned version, not inferred.
Basic Webpack 4+ configuration with ShakePlugin, including optional callbacks for export deletion and bailouts.
Use webpack-common-shake@1.x with Webpack 3, or upgrade to Webpack 4+.
Avoid dynamic property access on exports. Use static export assignments.
Do not reassign variables that hold required modules.
Assign require result to a variable before using.
Use static import paths and access properties directly.
Avoid dynamic require expressions.
npm install webpack-common-shake --save-dev
const ShakePlugin = require('webpack-common-shake').Plugin;Upgrade to Webpack 4+ or use webpack-common-shake@1.x.
Remove dynamic require or use onGlobalBailout to handle.