수색…


소개

배럴은 여러 ES2015 모듈에서 하나의 편리한 ES2015 모듈로 내보내기를 롤업하는 방법입니다. 배럴 자체는 다른 ES2015 모듈의 선택된 내보내기를 다시 내보내기하는 ES2015 모듈 파일입니다.

배럴 사용

예를 들어 배럴이 없으면 소비자는 세 가지 import 문이 필요합니다.

import { HeroComponent } from '../heroes/hero.component.ts';                                
import { Hero }          from '../heroes/hero.model.ts';                                      
import { HeroService }   from '../heroes/hero.service.ts';

동일한 구성 요소 폴더에 파일을 만들어 배럴을 추가 할 수 있습니다. 이 경우이 폴더는 다음 항목 모두를 내보내는 '영웅'이라는 이름의 index.ts (규칙을 사용)라고합니다.

export * from './hero.model.ts';   // re-export all of its exports
export * from './hero.service.ts'; // re-export all of its exports                           
export { HeroComponent } from './hero.component.ts'; // re-export the named thing

이제 소비자는 배럴에서 필요한 것을 가져올 수 있습니다.
import { Hero, HeroService } from '../heroes/index';

그래도 이것은 매우 긴 줄이 될 수 있습니다. 더 줄일 수 있습니다.

import * as h from '../heroes/index';

그것은 상당히 감소했습니다! * as h 모든 모듈과 별칭을 h로 가져옵니다.



Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow