CommonJS 의 트리쉐이킹(tree shaking)이 효율적이지 않은 이유

CommonJS 의 특징

1. 동적 require

const moduleName = 'some-module';
const someModule = require(moduleName);

2. 모듈 전체 가져오기

const myModule = require('./myModule');
const result = myModule.someFunction();

3. exports 객체의 동적 조작

if (condition) {
  module.exports = require('./moduleA');
} else {
  module.exports = require('./moduleB');
}

반면..ES moudle 은

ESM의 특징

1. 정적 구조

import { specificFunction } from './myModule';
specificFunction();

2. NamedExports

// myModule.js
export function specificFunction() { /* ... */ }
export function anotherFunction() { /* ... */ }