Configure the url of module federation
Currently, module federation points to localhost.
I see two options:
- Configure in static mode (hardcoded with the prod configuration)
- Read the variables from the env
I am tempted by the 2nd as it seems more elegant
vite.config.ts is:
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import tsconfigPaths from 'vite-tsconfig-paths';
import federation from '@originjs/vite-plugin-federation';
// https://vitejs.dev/config/
export default defineConfig({
build: {
modulePreload: false,
target: 'esnext',
minify: false,
cssCodeSplit: false,
},
plugins: [
react(),
tsconfigPaths(),
federation({
name: 'app',
remotes: {
remoteApp: 'http://localhost:3001/assets/remoteEntry.js',
logistics: 'http://localhost:3002/assets/remoteEntry.js',
cryoet: 'http://localhost:3003/assets/remoteEntry.js',
},
shared: [
'react',
'react-dom',
'@tanstack/react-query',
'react-router-dom',
],
}),
],
server: {
port: 3000,
},
define: {
'process.env': process.env,
},
});
Module federation will not work except if .env.prod is configured as it should be OR it is taken from the environment
Edited by Alejandro De Maria Antolinos