0Pricing
Micro Frontends Architecture with Module Federation · Pelajaran

Mengonfigurasi Dependensi Bersama

Pelajari cara opsi shared di Module Federation memungkinkan aplikasi host dan remote berbagi pustaka seperti React, sehingga unduhan ganda dan konflik versi dapat dihindari.

Mengonfigurasi Dependensi Bersama adalah pelajaran Micro Frontends Architecture with Module Federation gratis di CoddyKit. Ini adalah pelajaran 4 dari 4. Kamu bisa membaca pelajaran lengkapnya di bawah secara gratis — lalu praktikkan langsung di browser dengan editor kode bawaan dan tutor AI 24/7. Ini adalah bagian dari jalur belajar Micro Frontends Architecture with Module Federation, dan progresmu tersinkronisasi di web dan aplikasi CoddyKit. Kursus Micro Frontends Architecture with Module Federation mencakup 4 pelajaran total.

Bagian dari pelajaran ini belum diterjemahkan dan ditampilkan dalam bahasa Inggris.

The Duplication Problem

Without coordination, a host and each remote would each bundle their own copy of React, Lodash, and other libraries. Users would download the same code many times.

The shared option solves this.

What shared Does

The shared key in ModuleFederationPlugin tells webpack which dependencies should be loaded once and reused across federated apps at run time.

Basic shared Syntax

The simplest form lists package names as an array. Webpack then negotiates a single shared instance at run time.

new ModuleFederationPlugin({
  name: "host",
  shared: ["react", "react-dom"]
});

Object Form for Options

The object form gives fine-grained control per dependency, such as marking it required or singleton.

shared: {
  react: { singleton: true, requiredVersion: "^18.0.0" },
  "react-dom": { singleton: true }
}

The singleton Option

singleton: true forces every app to use ONE instance of the library. This is essential for React, whose hooks break if two copies load at once.

requiredVersion and Negotiation

Each app declares a requiredVersion. At run time Module Federation picks the highest version that satisfies everyone. If versions are incompatible, it warns or falls back.

shared: {
  react: { singleton: true, requiredVersion: "^18.2.0" }
}

The eager Option

eager: true bundles the shared dependency into the initial chunk instead of loading it asynchronously. Useful for the host shell but increases initial bundle size.

shared: {
  react: { singleton: true, eager: true }
}

Reading from package.json

To avoid hardcoding versions, you can derive them from your dependencies, keeping shared config in sync with what you actually install.

const deps = require("./package.json").dependencies;
shared: {
  react: { singleton: true, requiredVersion: deps.react }
}

strictVersion

strictVersion: true makes Module Federation throw instead of falling back when no compatible version is found — surfacing mismatches early during testing.

Common Pitfalls

Watch out for:

  • Forgetting singleton on React, causing hook errors
  • Mismatched major versions across remotes
  • Overusing eager, bloating the first load

Verifying Sharing Works

Open the browser network tab: if React loads only once across host and remotes, sharing is working. The webpack build log also reports shared-module resolution.

Quick Check

Test your shared-dependency knowledge.

Recap

You configured shared dependencies:

  • shared avoids duplicate libraries across apps
  • Use the object form for per-package control
  • singleton is critical for React and React-DOM
  • requiredVersion drives run-time negotiation
  • Use eager and strictVersion deliberately

Good sharing keeps federated apps fast and conflict-free.

Pertanyaan yang Sering Diajukan

Apakah pelajaran “Mengonfigurasi Dependensi Bersama” gratis?

Ya — teks lengkap “Mengonfigurasi Dependensi Bersama” gratis dibaca di sini di web. Untuk praktiknya secara interaktif (editor kode bawaan dan tutor AI 24/7) dan buka sisa kursus Micro Frontends Architecture with Module Federation, upgrade ke CoddyKit PRO. Kursus Micro Frontends Architecture with Module Federation mencakup 4 pelajaran total.

Apa yang akan aku pelajari di “Mengonfigurasi Dependensi Bersama”?

Pelajari cara opsi shared di Module Federation memungkinkan aplikasi host dan remote berbagi pustaka seperti React, sehingga unduhan ganda dan konflik versi dapat dihindari. Kamu berlatih Micro Frontends Architecture with Module Federation dengan kode praktik yang langsung kamu jalankan di browser, dan tutor AI 24/7 menjawab pertanyaanmu saat kamu mengerjakan pelajaran ini.

Apakah aku perlu pengalaman untuk memulai Micro Frontends Architecture with Module Federation?

Tidak diperlukan pengalaman sebelumnya. Micro Frontends Architecture with Module Federation di CoddyKit dirancang untuk pemula hingga pelajar tingkat lanjut, jadi kamu bisa memulai di sini atau dari awal dan belajar sesuai kecepatan kamu sendiri. Ini adalah pelajaran 4 dari 4.

Berapa lama pelajaran “Mengonfigurasi Dependensi Bersama” memakan waktu?

Sebagian besar pelajaran CoddyKit memakan waktu sekitar 5–10 menit. Setiap pelajaran ringkas dan interaktif, jadi kamu membuat kemajuan stabil dan melanjutkan dari tempat kamu tinggalkan di web dan aplikasi.

Bisakah aku menulis dan menjalankan kode dalam pelajaran Micro Frontends Architecture with Module Federation ini?

Ya. Setiap pelajaran Micro Frontends Architecture with Module Federation menyertakan editor kode bawaan, jadi kamu menulis dan menjalankan kode nyata langsung di browser dan mendapatkan umpan balik AI instan — tidak diperlukan penyiapan lokal.

Semua pelajaran dalam kursus ini

  1. Tinjauan Dasar-Dasar Webpack
  2. Memperkenalkan Module Federation
  3. Aplikasi Host dan Remote
  4. Mengonfigurasi Dependensi Bersama
← Kembali ke Micro Frontends Architecture with Module Federation