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 ModuleFederation({
      name: 'provider',
      exposes: {
        './Button': './src/components/Button.tsx',
      },
      // ...
      getPublicPath: `function() {return "https:" + window.navigator.cdn_host + "/resource/app/"}`,
    }),
  ],
};