Modern.js offers a comprehensive plugin system with a complete lifecycle. Plugins can be used to extend different stages of project operation, request handling, rendering, and more.
Plugins must be explicitly registered in the configuration file to be effective. When you need to add plugins to Modern.js, you can configure them in the [plugins](/configure/app/plugins.html)
field:
Note that this configuration only supports adding Modern.js plugins and does not support adding Webpack plugins.
Modern.js offers a range of official plugins, which are integrated with the Modern.js generator. All the functionalities of the official plugins can be enabled by executing the new
command. For instance, to enable the BFF (Backend For Frontend) feature:
After the selection is completed, the Modern.js generator will automatically install the corresponding plugins and third-party dependencies. Upon completion of the installation, you will see:
At this point, you can add the plugin to the configuration file according to the output in the console.
The Modern.js plugin system is mainly divided into three parts: Hook model, Manager, and Context Sharing Mechanism.
Currently, Modern.js offers several different Hook models: Pipeline, Waterfall, Workflow.
Subsequent chapters will introduce the execution methods of each model in detail.
Based on the Hook model and Manager, Modern.js exposes three sets of plugins: CLI, Runtime, and Server.
Among them, the CLI plugin is the main running flow control model in Modern.js, and most of the features in Modern.js are mainly run through this set of models. The Runtime plugin is mainly responsible for processing the rendering logic of React components. The Server plugin is mainly used for controlling the server lifecycle and user requests.
All of Modern.js's features are implemented through this set of plugins, which means that all of Modern.js's capabilities are open to developers. Developers can develop plugins to extend more functionality and adapt to complex scenarios, including but not limited to:
When Modern.js does not currently cover the functionality or scenario that you need, you can develop a custom plugin to implement the related functionality for adapting to special scenarios.