vite-plugin-federation icon indicating copy to clipboard operation
vite-plugin-federation copied to clipboard

Support dev server remote entry file

Open Darshan-Naik opened this issue 1 year ago • 5 comments

##Running dev should produce remoteEntry.js

currently, we can only use remote build files in the host. there is no way to use running dev remote to talk with the host app which is a pain point for the development productivity.

Darshan-Naik avatar Oct 09 '23 12:10 Darshan-Naik

This is a bit difficult to implement because vite dev is bundleless. Duplicate of #281

flyfishzy avatar Oct 09 '23 12:10 flyfishzy

I have run into this issue as well. By targeting the build directory I don't get hot reloading of the file a la nodemon + express.js. This means I have to rebuild to get the latest. Bummer.

adamsimonini avatar Jan 22 '24 18:01 adamsimonini

This is a workaround for me, but you have to manually refresh the host app whenever the sub app changes:

  • The host app: Terminal 1: npm run dev

  • The sub app: package.json: add "build:watch": "vite build --watch" Terminal 2: npm run build:watch Terminal 3: npm run preview

tuzkituan avatar Feb 02 '24 02:02 tuzkituan

in scripts section of your mf app: "micro": "vite build --watch & vite preview --port 5010 --strictPort", then you can just run yarn micro

marcin-kopanski avatar Mar 05 '24 12:03 marcin-kopanski

@tuzkituan

This is a workaround for me, but you have to manually refresh the host app whenever the sub app changes:

You can solve host refreshing issue by using 2 simple plugins for both sides:

remote side

{
  name: 'vite-plugin-notify-host-on-rebuild',
  apply(config, { command }) {
    return Boolean(command === 'build' && config.build?.watch);
  },
  async buildEnd(error) {
    if (!error) {
      try {
        await fetch('http://your-local-host-url-here/__fullReload');
      } catch (e) {
        // noop
      }
    }
  },
}

host side

{
  name: 'vite-plugin-reload-endpoint',
  configureServer(server) {
    server.middlewares.use((req, res, next) => {
      if (req.url === '/__fullReload') {
        server.hot.send({ type: 'full-reload' });

        res.end('Full reload triggered');
      } else {
        next();
      }
    });
  },
}

acupofspirt avatar Mar 20 '24 21:03 acupofspirt