Code Monkey home page Code Monkey logo

babel-webpack-tree-shaking's Introduction

Tree-shaking example with Babel and Webpack

This repository shows how to configure Babel and Webpack to enable tree-shaking for development and production builds.

It will eliminate dead code not used by other modules if they have ES2015 module format.

The source code can be found in the app/ folder, where the main file car.js doesn't use all the dependencies from engine.js. The built and transpiled files can be found in the /dist folder.

For development build run npm run webpack (ES2015 -> ES5 bundle).

For production build run npm run webpack-prod (ES2015 -> ES5 bundle -> UglifyJS).

For ES2015 development build run npm run webpack-es2015 (ES2015 -> ES2015 bundle).

For experimental production build run npm run webpack-es2015-prod (ES2015 -> ES2015 bundle -> Babili). It uses the Babili ES6+ aware minifier and solves the issues what UglifyJS has.

Will replace UglifyJS with Babili when it gets stable.

It uses babel-preset-latest, which includes ES2016 and ES2017 features also. If you want only ES2015 replace the presets in .babelrc to this:

"presets": [
  [
    "es2015",
    {
      "loose": true,
      "modules": false
    }
  ]
]

Requirements

  • babel-preset-es2015 >= 6.13.0 or babel-preset-latest
  • webpack >= 2.1.0-beta

Known issues

When transpiling classes with Babel, it generates an IIFE with an assignment to the prototype. It is considered as a side effect by UglifyJS and it skips removing of it.

See the issues below:

babel-webpack-tree-shaking's People

Contributors

swansontec avatar vuesomedev avatar

Watchers

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