logologo
Guide
Practice
Configuration
Plugins
Showcase
Blog
Ecosystem
Module Federation Examples
Practical Module Federation
Zephyr Cloud
Nx
简体中文
English
Guide
Practice
Configuration
Plugins
Showcase
Blog
Module Federation Examples
Practical Module Federation
Zephyr Cloud
Nx
简体中文
English
logologo
Overview
Name
Filename
Remotes
Exposes
Shared
runtimePlugins
Get Public Path
Implementation
DTS
Dev
Manifest
shareStrategy
experiments
Edit this page on GitHub
Previous PageruntimePlugins
Next PageImplementation

#GetPublicPath

  • Type: string

  • Required: No

  • Default value: undefined

  • Purpose: Used to set a dynamic publicPath. Once set, the corresponding remote module resources will also use this publicPath. For instance, if the deployed project dynamically serves a cdn_prefix, getPublicPath can be set to return "https:" + window.navigator.cdn_host + "/resource/app/".

  • Example:

In the example below, getPublicPath is set. When other consumers load this provider, the code for getPublicPath will be executed using new Function to obtain the return value. The content of the return value will be used as the publicPath prefix for the static resources of the module.

NOTE

getPublicPath Must be a function as a string.

NOTE

If you're using module federation webpack plugin and want to set a dynamic publicPath, you should set __webpack_public_path__ = window.cdn_prefix statement in getPublicPath function body.

rspack.config.ts
module.exports = {
  plugins: [
    new ModuleFederationPlugin({
      name: 'provider',
      exposes: {
        './Button': './src/components/Button.tsx',
      },
      // ...
      getPublicPath: `function() {return "https:" + window.navigator.cdn_host + "/resource/app/"}`,
    }),
  ],
};