ESM (ECMA Script Module)

- JavsScript의 양대 module system
- CJS (CommonJS)
- ESM (ECMA Module System)
- 이 둘을 동시에 지원하도록 library를 만들 수 있다
package.json의exports필드를 통해 지원
# CommonJS
- JavaScript 문법은 변경없이 API로 구현하는 느낌 (
module은 변수,require는 함수) - synchronous
- Tree shaking이 어렵다
- 명시적 file extension:
cjs,cts
| |
# ECMAScript Modules
- 새 문법을 도입하여 module을 지원 (
import,export같은 언어수준 keyword 추가) - asynchronous ( Top-level await 지원)
- Tree shaking이 쉽다
- 명시적 file extension:
.mjs,.mts
| |