Skip to content

[Feature Request]: share moduleRegistry cross multi entries #1559

@xusd320

Description

@xusd320

Problem:

When building multi entries for server-less functions (like Chair Function), some functions may share many modules. By code splitting, those shared modules will be bundled into a common chunk. Usually, the chunk group rule will be like:

{
  codeSplitting: {
    strategy: "advanced",
    options: {
      groups: [
        {
          name: "common",
          test: "common/.*",
          allowChunk: "all",
          minSize: 1
        }
      ]
    }
  }
}

In server-less functions, those multi entries may be require in a same nodejs process, and expect modules in the common chunk
will be single instance. Now time, our runtime mechanism will let common modules be isolated cross entries.

function createRuntime(makoModules, entryModuleId, global) {
  // modulesRegistry is in a closure, which will be isolated.
  var modulesRegistry = {};
   /* ... */
}

Solution 1:

Add an option to let runtime can get moduleRegistry from a global variable, the runtime code will be like:

global.__makoGlobalModuleRegistry = 
  process.env.globalModuleRegistry ? 
    (global.__makoGlobalModuleRegistry || {}) : 
     undefine;

function createRuntime(makoModules, entryModuleId, global) {
  var modulesRegistry = global.__makoGlobalModuleRegistry || {};
   /* ... */

}

Solution 2:

Add plugin mechanism for runtime template, let users can customize the runtime template.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions