GithubHelp home page GithubHelp logo

pchengxing / webpack-deep-scope-analysis-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vincentdchan/webpack-deep-scope-analysis-plugin

0.0 1.0 0.0 481 KB

A webpack plugin for deep scope analysis

TypeScript 81.06% JavaScript 18.94%

webpack-deep-scope-analysis-plugin's Introduction

Webpack Deep Scope Analysis Plugin

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

Demo: https://vincentdchan.github.io/webpack-deep-scope-demo/

Install

Install the plugin:

$ yarn add webpack-deep-scope-plugin

Require

  • Node.js 8 +
  • webpack 4.14.0 +

Usage

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.

Articles

Medium

中文版

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();

Changelog

v1.6.0

  • 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.

v1.5.4

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

v1.5.3

v1.5.2

  • Improve performance and code quality

v1.5.0

  • Introduce VirtualScope to simulate module variable

v1.4.0

  • Fix #4
  • Publish

Contributing

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.

webpack-deep-scope-analysis-plugin's People

Contributors

vincentdchan avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.