Загрузка...

Module Federation #javascript #frontend #webdeveloper #webpack #modulefederation #software

#JavaScript Module Federation is a feature that allows developers to dynamically share and use code between different JavaScript applications.

Webpack is a popular module bundler that provides this feature. It enables the creation of a federated system where multiple applications can collaborate and share modules at runtime.

Whats Webpack ?

Webpack is a powerful and widely used open-source JavaScript module bundler. It is a build tool that simplifies the process of managing and bundling assets, such as JavaScript, CSS, and images, for web applications.
Module Bundler ?

A module bundler is a tool that takes separate modules of code written in a modular programming language (like JavaScript) and bundles them together into a single file or a set of files.
The goal is to optimize the loading and execution of web applications by reducing the number of HTTP requests needed to retrieve individual files.
Federated system ?

A federated system, also known as a federated architecture, refers to a system that is composed of multiple independent entities or components that cooperate and work together while maintaining a degree of autonomy.
In a federated system, each component retains a level of self-governance and control, making decisions locally, but collaborates with others to achieve common goals.

https://github.com/module-federation
Key concepts
Remote Module Loading: Module Federation allows one application to load and use modules from another application at runtime. This means that code can be shared dynamically between different micro-frontends.
Shared Modules: Developers can define a list of shared modules that can be accessed by multiple micro-frontends. These shared modules are loaded once and can be used by any application that needs them.
Dynamic Imports: Module Federation uses dynamic imports to load modules on-demand, enabling a more efficient and optimized application loading process.
Example:
Consider a large web application that consists of multiple independently developed modules or micro-frontends. With dynamic sharing of code:

Module A might need a utility function from Module B.
Instead of bundling the entire Module B with Module A during the build process, Module A can dynamically load the specific function from Module B when needed.
This dynamic loading happens at runtime, allowing Module A to access and use the functionality from Module B on-demand.
Dynamic sharing of code is achieved through the use of dynamic imports and remote loading of modules. Modules can be exposed by one application and consumed by another at runtime, allowing for a more flexible and modular architecture.
Dynamic Loading benefits:
Dynamic loading allows a program to load and execute code at runtime rather than during the initial startup.

Traditionally, code is shared during the build or compile phase, resulting in a single bundled file. With dynamic sharing, the sharing happens on-the-fly, allowing parts of the application to use code from other parts as the application is running.
Efficient Resource Utilization:Dynamic sharing promotes efficient resource utilization by loading only the code that is necessary for a specific part of the application. This can result in better performance and a more responsive user experience.
Basic example of a Webpack configuration for Module Federation:
To implement Module Federation, you typically configure your Webpack build to expose specific modules and consume modules from other applications.

The configuration involves specifying which modules should be shared, which applications provide those modules, and how they should be loaded at runtime.

Why Module Federation? Use Cases ?

Developed and deployed independently: The key idea behind Module Federation is to break down a large application into smaller, more manageable pieces, called micro-frontends. Each micro-frontend is a separate JavaScript application that can be developed and deployed independently.
Faster builds and compile time
Drawbacks :

More complex code
Error Prone : As no compilation and build
#javascript #modulefederation #software
#softwaredevelopment Development
#frontenddevelopment End Development
#webdevelopment Development
#webpack

Видео Module Federation #javascript #frontend #webdeveloper #webpack #modulefederation #software канала 1minuteconcepts
Яндекс.Метрика

На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.

Об использовании CookiesПринять