File tree Expand file tree Collapse file tree 3 files changed +33
-12
lines changed
advanced-api/dynamic-remotes-synchronous-imports/app2 Expand file tree Collapse file tree 3 files changed +33
-12
lines changed Original file line number Diff line number Diff line change 1
- import { loadFromRemote } from "./loader" ;
2
1
import Widget from "./Widget" ;
3
- import React , { lazy , Suspense } from "react" ;
2
+ import React , { Suspense } from "react" ;
3
+ import WidgetRemote from "app3/Widget" ;
4
4
5
- const WidgetRemote = lazy ( async ( ) => {
6
- const component = await loadFromRemote ( {
7
- component : "Widget" , remote : {
8
- url : "http://localhost:3003/remoteEntry.js" ,
9
- name : "app3" ,
10
- } ,
11
- } ) ;
12
- return component ( ) ;
13
- } ) ;
5
+ // Working example of loading component at runtime
6
+ // import { loadFromRemote } from "./loader";
7
+ // const WidgetRemote = React.lazy(async () => {
8
+ // const component = await loadFromRemote({
9
+ // component: "Widget", remote: {
10
+ // url: "http://localhost:3003/remoteEntry.js",
11
+ // name: "app3",
12
+ // },
13
+ // });
14
+ // return component();
15
+ // });
14
16
15
17
const App = ( ) => (
16
18
< div >
Original file line number Diff line number Diff line change @@ -86,3 +86,11 @@ export const loadFromRemote = ({
86
86
} ;
87
87
} ;
88
88
89
+ const container = ( async ( ) => {
90
+ return await loadAndInitiateWebpackContainer ( {
91
+ name : "app3" ,
92
+ url : "http://localhost:3003/remoteEntry.js" ,
93
+ } ) ;
94
+ } ) ( ) ;
95
+
96
+ export default container ;
Original file line number Diff line number Diff line change @@ -2,8 +2,13 @@ const HtmlWebpackPlugin = require("html-webpack-plugin");
2
2
const { ModuleFederationPlugin } = require ( "webpack" ) . container ;
3
3
const path = require ( "path" ) ;
4
4
const deps = require ( "./package.json" ) . dependencies ;
5
+
5
6
module . exports = {
6
- entry : "./src/index" ,
7
+ entry : [
8
+ "./src/index" ,
9
+ // This seems necessary for module to even be available
10
+ "./src/loader.js"
11
+ ] ,
7
12
mode : "development" ,
8
13
target : "web" ,
9
14
devServer : {
@@ -32,6 +37,12 @@ module.exports = {
32
37
exposes : {
33
38
"./Widget" : "./src/Widget" ,
34
39
} ,
40
+ remotes : {
41
+ app3 : "internal ./src/loader.js"
42
+ // Use remote entry below to see working example with synchronous
43
+ // imports
44
+ // app3: "app3@//localhost:3003/remoteEntry.js"
45
+ } ,
35
46
shared : {
36
47
moment : deps . moment ,
37
48
react : {
You can’t perform that action at this time.
0 commit comments