Naming Convention

In order to increase the business modules continuously and achieve a highly reusable effect, the namespace of all modules must be fully isolated, to avoid mutual pollution and conflict. Thus the naming convention is as follows:

  1. 1egg-born-module-{providerId}-{moduleName}
Name Description
providerId It is strongly recommended to use the Username of GitHub as the Provider ID, so as to ensure that the modules contributed to the community will not conflict
moduleName module name

Based on this naming convention, module-related resources are referenced at the frontend and backend as follows:

Module egg-born-module-test-party as example:

Name Description
providerId test
moduleName party
fullName egg-born-module-test-party
relativeName test-party
frontend page route url /test/party/{page}
backend api route url /test/party/{controller}/{action}

Module Namespace Isolation

In order to adapt to the scenario of large-scale business development and avoid variable pollution and conflict between modules, the framework implements a module namespace isolation mechanism for both the frontend and the backend, including the frontend components, frontend configuration, backend logic, backend routing, backend configuration and other elements of the module (see the following chapters of module development)

Module Type

There are three types of modules in EggBornJS: Global Module, Local Module, Vendor Module

Name Description
Global Module path: {project}/node_modules
Local Module path: {project}/src/module
Vendor Module path: {project}/src/module-vendor

Create Module

If want to create a new module named as demo-student, enter the project path and run the cli command:

  1. 1$ cd /path/to/project
  2. 2$ npm run cli :create:module demo-student

Install Vendor Module

In general, vendor modules are provided by Cabloy Store. For example, Cabloy Store has a a-flow module (including node workflow engine codes). If you want to install this suite, just as follows:

  1. 1$ npm run cli :store:sync a-flow

Loading Mechanism

Backend Loading

EggBornJS implements a custom loader based on EggJS. When the system is started, all modules are loaded synchronously at one time, and the upgrade logic of module data version is automatically determined and completed

Frontend Loading

The module frontend supports both asynchronous loading and synchronous loading

Generally, the default is asynchronous loading

If you want to change it into synchronous loading, just add -sync suffix behind the module name, such as the module egg-born-module-a-components-sync

Module Dependencies

Manage module dependencies through the module’s file package.json

For example, module aa-module1 depends on aa-module2. Need to make the following configuration in the file package.json of module aa-module1

  1. 1{
  2. 2 "name": "egg-born-module-aa-module1",
  3. 3 "version": "0.0.1",
  4. 4 "eggBornModule": {
  5. 5 "dependencies": {
  6. 6 "aa-module2": "0.0.1"
  7. 7 }
  8. 8 }
  9. 9}
Name Description
“aa-module2”: “0.0.1” This declaration ensures the loading order between dependent modules