Webpack Deep Scope Analysis Plugin
raw JSON →Webpack plugin (npm package deep-scope-analyser v1.7.0, low activity) that improves tree-shaking by performing deep scope analysis to eliminate unused imports and exports. Designed for webpack 4.14.0+ and Node.js 8+. It solves webpack issue #6264 by analyzing variable scopes to determine which imports can be safely removed, beyond what webpack's built-in tree-shaking achieves. The plugin works only with ES module syntax (import/export) and requires the PURE annotation for side-effect marking. Originally named webpack-deep-scope-plugin (v1.5.x), renamed to deep-scope-analyser in v1.6.0 for standalone use. Maintained by a GSoC 2018 student, but has seen no updates since 2019. Differentiators: deeper analysis than standard tree-shaking; but limited to webpack 4 and ESM-only, with potential compatibility issues.
Common errors
error Module not found: Error: Can't resolve 'webpack-deep-scope-plugin' ↓
error TypeError: webpackDeepScopeAnalysisPlugin is not a constructor ↓
error Error: Cannot find module 'webpack' ↓
Warnings
breaking Renamed from webpack-deep-scope-plugin (v1.5.x) to deep-scope-analyser (v1.6.0). Existing import paths break. ↓
deprecated Package has not been updated since 2019; may be incompatible with webpack 5 and modern Node.js (>=14). ↓
gotcha The plugin only works with ES module syntax (import/export). If Babel or TypeScript transpile to CommonJS (require/module.exports), the analysis fails silently. ↓
gotcha CommonJS require('webpack-deep-scope-plugin') returns an empty object; must use .default property. ↓
Install
npm install deep-scope-analyser yarn add deep-scope-analyser pnpm add deep-scope-analyser Imports
- default wrong
import { WebpackDeepScopeAnalysisPlugin } from 'webpack-deep-scope-plugin';correctimport WebpackDeepScopeAnalysisPlugin from 'webpack-deep-scope-plugin'; - default wrong
const WebpackDeepScopeAnalysisPlugin = require('webpack-deep-scope-plugin');correctconst WebpackDeepScopeAnalysisPlugin = require('webpack-deep-scope-plugin').default; - default wrong
import { default as WebpackDeepScopeAnalysisPlugin } from 'deep-scope-analyser';correctimport WebpackDeepScopeAnalysisPlugin from 'deep-scope-analyser';
Quickstart
// webpack.config.js
const WebpackDeepScopeAnalysisPlugin = require('webpack-deep-scope-plugin').default;
module.exports = {
mode: 'production',
entry: './src/index.js',
output: {
path: __dirname + '/dist',
filename: 'bundle.js'
},
plugins: [
new WebpackDeepScopeAnalysisPlugin()
]
};