Description
I am trying to migrate from webpack to vite. It's mostly working, except one issue, when the host and remote are deployed on separate domains.
Minimal reproduction: https://github.com/lmiller1990/vite-module-federation-bug
There is a bug where, for production builds (not vite dev
) the host will preload assets from its own domain. The remote IS able to load exposed assets from the host, though. Weird!
You can reproduce this by running ./reproduction.sh
:
chmod +x reproduction.sh
./reproduction.sh
This will do a non minified, production build, and serve both apps using the serve
static server.
Visiting the remote, http://localhost:4000
, is fine. It loads a remote module exposed from the host, http://localhost:3000
, which logs a greeting (see the console).
Visitng the host, http://localhost:3000
, however, shows the issue. The preload-helper
tries to load the remote asset, such as place.js
, from http://localhost:3000/assets/place-DpMnJR6N.js
- it should be from http://localhost:4000/assets/place-DpMnJR6N.js
.
The problem is more clear when you look at the preload
code:
const scriptRel = 'modulepreload';
const assetsURL = function(dep) { return "/" + dep };
All assets are preloaded from /
.
This does NOT happen with vite dev
. If the domains are the same, it works as expected:
- host: https://lmiller1990.github.io/mfe-host/
- client: https://lmiller1990.github.io/mfe-client/ (see console for logging function, imported from host)