@@ -6,37 +6,84 @@ import type { Compiler } from '@rspack/core'
66
77import 'react-router'
88
9- class RuntimePlugin {
10- apply ( compiler : Compiler ) {
11- const { RuntimeGlobals } = compiler . webpack ;
12- compiler . hooks . compilation . tap ( 'CustomPlugin' , compilation => {
13- compiler . options . devtool = false
14- compilation . hooks . runtimeModule . tap (
15- 'CustomPlugin' ,
16- ( module : any , chunk : any ) => {
17- if ( module . name === "module_chunk_loading" ) {
18- const interceptor = `
19- console.log('test');
20- var getModuleUrl = function() {
21- console.log('Getting module URL', import.meta.url);
22- return import.meta.url;
23- };
24-
25- var importInterceptor = function(path) {
26- var currentUrl = getModuleUrl();
27- console.log('Importing:', path);
28- console.log('From module:', currentUrl);
29- return import(path);
30- };\n
31- `
32- module . source . source = interceptor + module . source . source . replace ( / i m p o r t \( / g, 'importInterceptor(' ) ;
33- }
34- }
35- ) ;
36- } ) ;
9+
10+ // Common shared dependencies for Module Federation
11+ const sharedDependencies = {
12+ 'react-router' : {
13+ singleton : true ,
14+ } ,
15+ 'react-router/' : {
16+ singleton : true ,
17+ } ,
18+ react : {
19+ singleton : true ,
20+ } ,
21+ 'react/' : {
22+ singleton : true ,
23+ } ,
24+ 'react-dom' : {
25+ singleton : true ,
26+ } ,
27+ 'react-dom/' : {
28+ singleton : true ,
29+ } ,
30+ }
31+
32+ // Common exposed components
33+ const exposedComponents = {
34+ './components/search-bar' : './app/components/search-bar' ,
35+ './components/user-dropdown' : './app/components/user-dropdown' ,
36+ './components/spacer' : './app/components/spacer' ,
37+ './components/toaster' : './app/components/toaster' ,
38+ './components/error-boundary' : './app/components/error-boundary' ,
39+ './components/floating-toolbar' : './app/components/floating-toolbar' ,
40+ './components/forms' : './app/components/forms' ,
41+ './components/progress-bar' : './app/components/progress-bar' ,
42+ './components/ui/tooltip' : './app/components/ui/tooltip' ,
43+ './components/ui/status-button' : './app/components/ui/status-button' ,
44+ './components/ui/textarea' : './app/components/ui/textarea' ,
45+ './components/ui/sonner' : './app/components/ui/sonner' ,
46+ './components/ui/label' : './app/components/ui/label' ,
47+ './components/ui/input' : './app/components/ui/input' ,
48+ './components/ui/input-otp' : './app/components/ui/input-otp' ,
49+ './components/ui/dropdown-menu' : './app/components/ui/dropdown-menu' ,
50+ './components/ui/icon' : './app/components/ui/icon' ,
51+ './components/ui/button' : './app/components/ui/button' ,
52+ './components/ui/checkbox' : './app/components/ui/checkbox' ,
53+ "./utils/connections" : "./app/utils/connections" ,
54+ }
55+
56+ // Common Module Federation configuration
57+ const commonFederationConfig = {
58+ name : 'remote' ,
59+ shareStrategy : "loaded-first" as const ,
60+ runtime : false ,
61+ exposes : exposedComponents ,
62+ shared : sharedDependencies ,
63+ manifest : {
64+ filePath : 'static'
3765 }
3866}
3967
68+ // Web-specific federation config
69+ const webFederationConfig = {
70+ ...commonFederationConfig ,
71+ library : {
72+ type : 'module'
73+ } ,
74+ }
75+
76+ // Node-specific federation config
77+ const nodeFederationConfig = {
78+ ...commonFederationConfig ,
79+ library : {
80+ type : 'commonjs-module'
81+ } ,
82+ runtimePlugins : [
83+ '@module-federation/node/runtimePlugin'
84+ ] ,
85+ }
86+
4087export default defineConfig ( {
4188 dev : {
4289 client : {
@@ -58,121 +105,20 @@ export default defineConfig({
58105 tools : {
59106 rspack : {
60107 plugins : [
61- new ModuleFederationPlugin ( {
62- name : 'remote' ,
63- library : {
64- type : 'module'
65- } ,
66- shareStrategy : "loaded-first" ,
67- runtime : false ,
68- manifest : {
69- filePath : 'static'
70- } ,
71- exposes : {
72- './components/search-bar' : './app/components/search-bar' ,
73- './components/user-dropdown' : './app/components/user-dropdown' ,
74- './components/spacer' : './app/components/spacer' ,
75- './components/toaster' : './app/components/toaster' ,
76- './components/error-boundary' : './app/components/error-boundary' ,
77- './components/floating-toolbar' : './app/components/floating-toolbar' ,
78- './components/forms' : './app/components/forms' ,
79- './components/progress-bar' : './app/components/progress-bar' ,
80- './components/ui/tooltip' : './app/components/ui/tooltip' ,
81- './components/ui/status-button' : './app/components/ui/status-button' ,
82- './components/ui/textarea' : './app/components/ui/textarea' ,
83- './components/ui/sonner' : './app/components/ui/sonner' ,
84- './components/ui/label' : './app/components/ui/label' ,
85- './components/ui/input' : './app/components/ui/input' ,
86- './components/ui/input-otp' : './app/components/ui/input-otp' ,
87- './components/ui/dropdown-menu' : './app/components/ui/dropdown-menu' ,
88- './components/ui/icon' : './app/components/ui/icon' ,
89- './components/ui/button' : './app/components/ui/button' ,
90- './components/ui/checkbox' : './app/components/ui/checkbox' ,
91- } ,
92- shared : {
93- 'react-router' : {
94- singleton : true ,
95- } ,
96- 'react-router/' : {
97- singleton : true ,
98- } ,
99- react : {
100- singleton : true ,
101- } ,
102- 'react/' : {
103- singleton : true ,
104- } ,
105- 'react-dom' : {
106- singleton : true ,
107- } ,
108- 'react-dom/' : {
109- singleton : true ,
110- } ,
111- }
112- } )
108+ new ModuleFederationPlugin ( webFederationConfig )
113109 ]
114110 }
115111 } ,
116112 plugins : [ ]
117113 } ,
118114 node : {
115+ output : {
116+ assetPrefix : 'http://localhost:3001/' ,
117+ } ,
119118 tools : {
120119 rspack : {
121120 plugins : [
122- new ModuleFederationPlugin ( {
123- name : 'remote' ,
124- library : {
125- type : 'commonjs-module'
126- } ,
127- manifest : {
128- filePath : 'static'
129- } ,
130- runtimePlugins : [
131- '@module-federation/node/runtimePlugin'
132- ] ,
133- runtime : false ,
134- exposes : {
135- './components/search-bar' : './app/components/search-bar' ,
136- './components/user-dropdown' : './app/components/user-dropdown' ,
137- './components/spacer' : './app/components/spacer' ,
138- './components/toaster' : './app/components/toaster' ,
139- './components/error-boundary' : './app/components/error-boundary' ,
140- './components/floating-toolbar' : './app/components/floating-toolbar' ,
141- './components/forms' : './app/components/forms' ,
142- './components/progress-bar' : './app/components/progress-bar' ,
143- './components/ui/tooltip' : './app/components/ui/tooltip' ,
144- './components/ui/status-button' : './app/components/ui/status-button' ,
145- './components/ui/textarea' : './app/components/ui/textarea' ,
146- './components/ui/sonner' : './app/components/ui/sonner' ,
147- './components/ui/label' : './app/components/ui/label' ,
148- './components/ui/input' : './app/components/ui/input' ,
149- './components/ui/input-otp' : './app/components/ui/input-otp' ,
150- './components/ui/dropdown-menu' : './app/components/ui/dropdown-menu' ,
151- './components/ui/icon' : './app/components/ui/icon' ,
152- './components/ui/button' : './app/components/ui/button' ,
153- './components/ui/checkbox' : './app/components/ui/checkbox' ,
154- } ,
155- shared : {
156- 'react-router' : {
157- singleton : true ,
158- } ,
159- 'react-router/' : {
160- singleton : true ,
161- } ,
162- react : {
163- singleton : true ,
164- } ,
165- 'react/' : {
166- singleton : true ,
167- } ,
168- 'react-dom' : {
169- singleton : true ,
170- } ,
171- 'react-dom/' : {
172- singleton : true ,
173- } ,
174- }
175- } )
121+ new ModuleFederationPlugin ( nodeFederationConfig )
176122 ]
177123 }
178124 } ,
0 commit comments