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" ;
21import Widget from "./Widget" ;
3- import React , { lazy , Suspense } from "react" ;
2+ import React , { Suspense } from "react" ;
3+ import WidgetRemote from "app3/Widget" ;
44
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+ // });
1416
1517const App = ( ) => (
1618 < div >
Original file line number Diff line number Diff line change @@ -86,3 +86,11 @@ export const loadFromRemote = ({
8686 } ;
8787} ;
8888
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");
22const { ModuleFederationPlugin } = require ( "webpack" ) . container ;
33const path = require ( "path" ) ;
44const deps = require ( "./package.json" ) . dependencies ;
5+
56module . 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+ ] ,
712 mode : "development" ,
813 target : "web" ,
914 devServer : {
@@ -32,6 +37,12 @@ module.exports = {
3237 exposes : {
3338 "./Widget" : "./src/Widget" ,
3439 } ,
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+ } ,
3546 shared : {
3647 moment : deps . moment ,
3748 react : {
You can’t perform that action at this time.
0 commit comments