Skip to content

Instantly share code, notes, and snippets.

@LeanSeverino1022
Created July 27, 2020 16:50
Show Gist options
  • Save LeanSeverino1022/3e2d2092461e197931f5e89b08c5d890 to your computer and use it in GitHub Desktop.
Save LeanSeverino1022/3e2d2092461e197931f5e89b08c5d890 to your computer and use it in GitHub Desktop.
test
import * as say from './say.js';

say.sayHi('John');
say.sayBye('John');
  1. Modern build tools (webpack and others) bundle modules together and optimize them to speedup loading and remove unused stuff.

    Let’s say, we added a 3rd-party library say.js to our project with many functions:

    // 📁 say.js
    export function sayHi() { ... }
    export function sayBye() { ... }
    export function becomeSilent() { ... }

    Now if we only use one of say.js functions in our project:

    // 📁 main.js
    import {sayHi} from './say.js';

    …Then the optimizer will see that and remove the other functions from the bundled code, thus making the build smaller. That is called “tree-shaking”.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment