Skip to content

The import paths in the built remote entry file do not use the base path configured in vite.config. #217

Open
@baijunjie

Description

Under normal circumstances, the reference paths for resource files built by a plugin should align with the base path specified in the Vite config.

The filename of the exposed remote module usually doesn't include a hash because it's the entry point for remote modules and needs to be accessible by external applications. Therefore, it is typically deployed separately on Nginx, while other resources are placed on a CDN. If a relative path is used, it can cause a bug where files can't be found.

vite.config.js

import { federation } from '@module-federation/vite'

export default {
  base: 'https://cdn.example.com/project-name',
  ...
  plugins: [
    federation({
      name: 'remote',
      filename: 'remote.js',
      exposes: {
        './preload': './src/preload',
      },
      shared: [],
    }),
  ],
}

output remote.js

image

Metadata

Assignees

No one assigned

    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