Skip to content


Folders and files

Last commit message
Last commit date

Latest commit


Repository files navigation

Webpack Deep Scope Analysis Plugin

This project is not maintained.

TLDR: This plugin will break your code, please use webpack5 instead.

This plugin can not work perfectly with webpack4. It will break your code in some cases. Webpack5 covers all the features implemented by this plugin, using wepback5 is a wise choice.

The reason according to sokra:

With DependencyReference returning null you prevent the module to be part of the chunk, but the Dependency doesn't know about that and always generates code to reference the module and try to load it at runtime. But there is no way to tell the Dependency that.

npm version

A webpack plugin for deep scope analysis. It's a project of GSoC 2018 webpack organization.

It's a plugin to improve tree-shaking. It can make webpack eliminate the unused imports related to the unused exports. It solves the issue 6254 for webpack.

Student: @Vincent Mentor: @Tobias



Install the plugin:

$ yarn add webpack-deep-scope-plugin


  • Node.js 8 +
  • webpack 4.14.0 +


Enable the plugin in webpack.config.js:

const WebpackDeepScopeAnalysisPlugin = require('webpack-deep-scope-plugin').default;

module.exports = {
  plugins: [
    new WebpackDeepScopeAnalysisPlugin(),

Notice: the plugin only works for import and export syntax module. If your code are transpiled to module.export and require syntax, the analyzer can't work correctly.

The plugin will analyze the scope and determine if the variables should be imported automatically.




Pure Annotation

As you know, it's difficult for ECMAScript to analyze the side effects. Hence, PURE annotation is introduced, which is from Uglify:

A function call is marked as "pure" if a comment annotation /*@__PURE__*/ or /*#__PURE__*/ immediately precedes the call. For example: /*@__PURE__*/foo();



  • Fix: #10


  • Upgrade tslint for security issue
  • Fix: #12 : Add README to npm


  • rename package webpack-deep-scope-analysis to deep-scope-analyser, which is published as a new npm package. It's aimed to be a standalone analyser.


  • Fix #7: import * from 'xxx' syntax



  • Improve performance and code quality


  • Introduce VirtualScope to simulate module variable


  • Fix #4
  • Publish


Use lerna to build and test:

$ lerna run build
$ lerna run tslint
$ lerna run test

About Escope

Now the src/ includes a Typescript version of escope, because the plugin needs some internal changes of the escope manager. So I didn't import the escope directly.

When the plugin is nearly finished, I will make some PRs to the original escope repo.