공유 종속성과 버전 관리
Module Federation이 마이크로 프런트엔드 간에 라이브러리를 공유하는 방식, 싱글턴과 버전 협상 방식, 중복 번들과 실행 중 오류를 방지하는 모범 사례를 배웁니다.
공유 종속성과 버전 관리은(는) CoddyKit의 무료 Micro Frontends Architecture with Module Federation 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Micro Frontends Architecture with Module Federation 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Micro Frontends Architecture with Module Federation 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
Why Sharing Matters
In a Module Federation setup every remote can bundle its own copy of react, react-dom, or a design system. Without coordination, a single page may load three copies of React.
Shared dependencies let independently deployed apps agree on a single instance of a library at runtime, cutting payload and avoiding state bugs.
The shared Key
Both host and remotes declare a shared block in their ModuleFederationPlugin config. Webpack then negotiates which version actually loads.
new ModuleFederationPlugin({
name: 'host',
shared: {
react: { singleton: true },
'react-dom': { singleton: true }
}
})Singletons Explained
singleton: true forces one and only one copy across the whole app. This is essential for libraries that hold internal state, like React (hooks) or a router.
Without it, two React instances cause the dreaded Invalid hook call error.
Version Negotiation
Each shared module declares a requiredVersion. At load time Module Federation picks the highest compatible version among all that are offered.
shared: {
react: {
singleton: true,
requiredVersion: '^18.2.0'
}
}Strict Version Mismatch
When a remote needs a version incompatible with the loaded singleton, Module Federation logs a warning and uses the existing one. With strictVersion: true it instead throws, surfacing the mismatch early.
shared: {
react: { singleton: true, strictVersion: true, requiredVersion: '18.2.0' }
}Eager vs Lazy Sharing
By default shared modules load asynchronously, which requires a bootstrap entry. Setting eager: true bundles the dependency into the initial chunk so no async boundary is needed.
Use eager only for the host shell; eager everywhere defeats the purpose of sharing.
shared: {
react: { singleton: true, eager: true }
}The bootstrap Pattern
Because shared modules resolve asynchronously, the standard pattern splits the entry into index.js (just an import) and bootstrap.js (the real app). This defers execution until the share scope is ready.
// index.js
import('./bootstrap');
// bootstrap.js
import App from './App';
// ... mount AppSharing a Design System
A shared component library should usually be a singleton too, so theming context and CSS-in-JS instances are not duplicated.
shared: {
'@acme/ui': { singleton: true, requiredVersion: '^3.0.0' }
}Auto-Sharing from package.json
Instead of listing versions by hand, you can pass an array and let the plugin read versions from package.json. Tools like the Module Federation Enhanced plugin can even auto-share all dependencies.
shared: ['react', 'react-dom', 'react-router-dom']Diagnosing Duplicate Copies
To confirm sharing works, inspect the Network tab: you should see one vendor chunk for the shared lib. Bundle analyzers and the runtime share scope (__webpack_share_scopes__.default) help debug.
Best Practices Summary
- Singleton for stateful libs (React, router, stores).
- Set
requiredVersionto align teams. - Keep
eageronly on the host shell. - Audit bundles regularly for accidental duplicates.
Quick Check
Which option ensures only one instance of React loads across all micro frontends?
Recap
You learned how Module Federation shares dependencies: singletons for stateful libs, version negotiation via requiredVersion/strictVersion, eager vs lazy loading, and the bootstrap pattern. Proper sharing slashes bundle size and prevents subtle runtime bugs.
자주 묻는 질문
“공유 종속성과 버전 관리” 강의는 무료인가요?
네 — “공유 종속성과 버전 관리” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Micro Frontends Architecture with Module Federation 강의 전체를 잠금 해제할 수 있습니다. Micro Frontends Architecture with Module Federation 강의에는 총 4개의 강의가 포함되어 있습니다.
“공유 종속성과 버전 관리”에서 뭘 배우나요?
Module Federation이 마이크로 프런트엔드 간에 라이브러리를 공유하는 방식, 싱글턴과 버전 협상 방식, 중복 번들과 실행 중 오류를 방지하는 모범 사례를 배웁니다. 브라우저에서 직접 실행하는 실습 코드로 Micro Frontends Architecture with Module Federation을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Micro Frontends Architecture with Module Federation을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Micro Frontends Architecture with Module Federation은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 4번째 강의입니다.
“공유 종속성과 버전 관리” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Micro Frontends Architecture with Module Federation 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Micro Frontends Architecture with Module Federation 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- 모노레포와 폴리레포 비교
- 조직 차원의 과제와 해결책
- 마이크로 프런트엔드와 모듈 연합의 미래
- 공유 종속성과 버전 관리