Rollup은 작은 코드 조각들을 효율적인 라이브러리나 복잡한 애플리케이션 번들로 컴파일하는 JavaScript 모듈 번들러입니다.
기본 설정 (rollup.config.mjs)
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import terser from '@rollup/plugin-terser';
export default {
input: 'src/index.js',
output: [
{ file: 'dist/bundle.cjs.js', format: 'cjs' },
{ file: 'dist/bundle.esm.js', format: 'es' },
{ file: 'dist/bundle.min.js', format: 'umd', name: 'MyLibrary', plugins: [terser()] }
],
plugins: [resolve(), commonjs()],
external: ['react', 'react-dom']
};
출력 포맷 비교 (Output Formats)
| Format | Option | Target |
|---|---|---|
| ES Module | es / esm |
import / export |
| CommonJS | cjs |
Node.js (require) |
| UMD | umd |
Browser / AMD / CJS |
| IIFE | iife |
Global Browser Bundle |
CLI 명령어 및 필수 플러그인
# Bundle with configuration file
npx rollup -c
# Watch for changes and rebuild automatically
npx rollup -c -w
# Override environment variables
npx rollup -c --environment BUILD:production
@rollup/plugin-node-resolve: Resolves third-party modules innode_modules.@rollup/plugin-commonjs: Converts CommonJS modules to ES6.@rollup/plugin-typescript: Compiles TypeScript files.@rollup/plugin-terser: Minifies output bundles.