Flutter 기준
flutter pub run build_runner build
맨날 fastapi server에서 init.py에서 경로로 빼주는게 있었는데 그게 배럴파일화한다는 것이였다..
next js의 경우 index.ts로 루트 경로마다 빼주는거....
import { InnerSection } from '@/_components/InnerSection/InnerSection'
import { LevelCard } from '@/_components/LevelCard/LevelCard'
import { NextStepButton } from '@/_components/NextStepButton/NextStepButton'
이런게
import { InnerSection, LevelCard, NextStepButton } from '@/_components'
이렇게 된다고한다...
자세한 건.. Barrel 파일 왜 쓰시나요? 여기서 잘 써준 형꺼 보기..
참조하는 부분도 코드가 줄어서 번들링 할 때 사이즈가 줄어드는듯
ESM 기반 배럴 파일을 쓰면, tree-shaking이 잘 작동하여 번들 사이즈가 줄어들 수 있다고함.
실제로 쓰이지 않는 코드(함수, 변수, 컴포넌트 등)를 최종 번들 파일에서 자동으로 제거하는 기능이라고함.
// utils.ts
export function add(a: number, b: number) {
return a + b;
}
export function multiply(a: number, b: number) {
return a * b;
}
// main.ts
import { add } from './utils';
console.log(add(2, 3));
이 때, multiply는 사용되지 않았기 때문에 tree-shaking이 작동하면 multiply는 번들 파일에 포함되지 않음!
flutter pub run build_runner build
flutter pub run build_runner build