exposes

  • Type: PluginExposesOptions
  • Required: No
  • Default value: undefined
  • Usage: Determines the modules and file entries exposed by Module Federation.
Tip

A producer-specific parameter, setting exposes indicates that this is a producer.

After configuration, the exposed modules will be separated into a distinct chunk, and if there are any asynchronous chunks, they will be extracted into individual chunks as well (the specific extraction behavior depends on the chunk splitting rules).

The PluginExposesOptions type is as follows:

interface PluginExposesOptions {
  [exposeKey: string]: string | ExposesConfig;
}

interface ExposesConfig {
  // File entry
  import: string;
  // Layer in which to build the exposed module
  layer?: string;
}

The exposeKey is essentially consistent with the Package Entry Points specification (except for not supporting regular expression matching). Example usage:

module.exports = {
  plugins: [
    new ModuleFederationPlugin({
      name: 'provider',
      exposes: {
        // Note: "./" is not supported. Exporting as `.` indicates a default export
        '.': './src/index.tsx',
        './add': './src/utils/add.ts',
        './Button': './src/components/Button.tsx',
      },
    }),
  ],
};

Use layer in the object form to build an exposed module in a named layer:

exposes: {
  './Server': { import: './src/Server.ts', layer: 'server' },
}

Layer names must be nonempty. With Webpack, enable experiments.layers. Omitting layer preserves the bundler's existing layer behavior; string exposes continue to work unchanged.