import * as say from './say.js';
say.sayHi('John');
say.sayBye('John');
-
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”.