originjs / vite-plugin-federation

Module Federation for vite & rollup

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Skip import of preload-helper in remoteEntry, if modulePreload is not set to false

zzlatkov92 opened this issue · comments

When building my application on top of the remoteEntry I have this line import{_ as i}from"./preload-helper-7dcba38e.js". As you can see from my configuration, I don't have modulePreload set to false and either way I have this import at the end.

The problem is that when I run my application in production, the preload-helper, can no longer be located relatively to the remoteEntry.

So my question is, is there a way, where I can avoid having this behavior ?

Versions

  • vite-plugin-federation: 1.3.2
  • vite: 4.5.0

Reproduction

I cannot share a reproduction of the problem

Additional Details
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react-swc';
import federation from '@originjs/vite-plugin-federation';
import pkg from './package.json';

const deps = pkg.dependencies;
const basePath = process.env.BASE_PATH || 'http://localhost:3000/ui/remote/';

// https://vitejs.dev/config/
export default defineConfig({
  base: basePath,
  build: {
    outDir: 'build',
    assetsDir: '',
    target: 'esnext'
  },
  plugins: [
    react(),
    federation({
      name: 'remote',
      filename: 'remoteEntry.js',
      exposes: {
        './REMOTE': './src/index.tsx'
      },
      shared: {
        react: {
          singleton: true,
          requiredVersion: deps['react']
        },
        'react-dom': {
          singleton: true,
          requiredVersion: deps['react-dom']
        },
        '@tanstack/react-query': {
          singleton: true,
          requiredVersion: deps['@tanstack/react-query']
        }
      }
    })
  ],
  server: {
    port: 3000,
    headers: {
      'Access-Control-Allow-Origin': '*',
      'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
      'Access-Control-Allow-Headers': 'X-Requested-With, content-type, Authorization'
    }
  }
});

Steps to reproduce

  • Build an application with the config above

What is Expected?

  • if modulePreload is not set to false, not to have import of preload-helper, relative to the remoteEntry.

What is actually happening?

  • remoteEntry is trying to import preload-helper relatively to it's location.