0Pricing
Micro Frontends Architecture with Module Federation · บทเรียน

แอปพลิเคชันโฮสต์และรีโมต

เรียนรู้ความแตกต่างระหว่างแอปพลิเคชันโฮสต์กับแอปพลิเคชันรีโมตในการตั้งค่าแบบสหพันธ์ รวมถึงบทบาทของแต่ละส่วน

แอปพลิเคชันโฮสต์และรีโมต เป็นบทเรียน Micro Frontends Architecture with Module Federation ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Micro Frontends Architecture with Module Federation และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Micro Frontends Architecture with Module Federation มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

What are Hosts & Remotes?

In Module Federation, applications play distinct roles: some are hosts, and others are remotes. Think of it like a main stage (host) that invites guest performers (remotes) to share their acts.

This setup allows large applications to be broken down into smaller, independently developed and deployed pieces.

The Host: Your Main App

The Host application is the primary application that boots up first. Its main job is to consume (or load) modules that are exposed by other applications, called Remotes.

It's like the main website that pulls in different widgets or sections from other services.

Host's Key Responsibilities

The Host application has a few crucial responsibilities:

  • Loading Remotes: It tells Webpack which remote applications it needs to load.
  • Providing Context: It often provides the overall application shell, routing, and shared dependencies.
  • Integrating Modules: It renders components or uses functions provided by the remote applications.

The Remote: A Shared Piece

A Remote application is a separate, self-contained application that exposes specific parts of its code for others to consume. It can also consume modules from other remotes (or even act as a host itself!).

These exposed parts could be components, utility functions, or even entire pages.

Remote's Key Responsibilities

The Remote application focuses on:

  • Developing Features: It builds specific features or UI components independently.
  • Exposing Modules: It explicitly defines which parts of its codebase can be shared with host applications.
  • Independent Deployment: It can be built and deployed without affecting the host or other remotes, as long as its exposed interfaces remain consistent.

ModuleFederationPlugin: The Link

Webpack's ModuleFederationPlugin is the magic behind this interaction. Both host and remote applications use this plugin in their Webpack configurations.

It orchestrates how modules are exposed by remotes and consumed by hosts, making them available at runtime.

Remote: Exposing Modules

On the Remote side, you use the exposes property in the ModuleFederationPlugin configuration.

This tells Webpack which files or modules from your remote application should be made available to others.

// webpack.config.js (remote app)
new ModuleFederationPlugin({
  name: 'remoteApp',
  exposes: {
    './Button': './src/Button.js',
    './Header': './src/Header.js'
  }
})

Host: Consuming Remotes

On the Host side, you use the remotes property to declare which remote applications you want to consume from.

You specify a unique name for the remote and its entry point URL.

// webpack.config.js (host app)
new ModuleFederationPlugin({
  name: 'hostApp',
  remotes: {
    remoteApp: 'remoteApp@http://localhost:3001/remoteEntry.js'
  }
})

How They Interact

When the Host application loads, it fetches the remoteEntry.js file from the configured remote URL. This entry file contains a manifest of all modules the remote exposes.

The Host can then dynamically import and use these exposed modules as if they were part of its own codebase.

Quick Check

Which of the following best describes the primary role of a Host application in a Module Federation setup?

Host & Remote Recap

We've learned about the fundamental roles of Host and Remote applications in Module Federation.

  • Host apps are the main integrators, consuming functionality.
  • Remote apps are independent units that expose specific modules.

Understanding these roles is key to building scalable micro frontends. Next, we'll dive deeper into setting up your first federated application!

คำถามที่พบบ่อย

บทเรียน “แอปพลิเคชันโฮสต์และรีโมต” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “แอปพลิเคชันโฮสต์และรีโมต” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Micro Frontends Architecture with Module Federation ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Micro Frontends Architecture with Module Federation มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “แอปพลิเคชันโฮสต์และรีโมต”

เรียนรู้ความแตกต่างระหว่างแอปพลิเคชันโฮสต์กับแอปพลิเคชันรีโมตในการตั้งค่าแบบสหพันธ์ รวมถึงบทบาทของแต่ละส่วน คุณปฏิบัติ Micro Frontends Architecture with Module Federation ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Micro Frontends Architecture with Module Federation หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Micro Frontends Architecture with Module Federation บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน

บทเรียน “แอปพลิเคชันโฮสต์และรีโมต” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Micro Frontends Architecture with Module Federation นี้ได้ไหม

ได้ บทเรียน Micro Frontends Architecture with Module Federation ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. ทบทวนพื้นฐาน Webpack
  2. รู้จัก Module Federation
  3. แอปพลิเคชันโฮสต์และรีโมต
  4. การกำหนดค่าการพึ่งพาร่วม
← กลับไปที่ Micro Frontends Architecture with Module Federation