-
Notifications
You must be signed in to change notification settings - Fork 14
Using systemjs as module loader #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
b587475
0fdd090
0676291
1997785
24034e7
7072d34
f313f4c
7196aa6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,24 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <script src="http://localhost:3002/remoteEntry.js"></script> | ||
| <script src="http://localhost:3003/remoteEntry.js"></script> | ||
| <script type="systemjs-importmap"> | ||
| { | ||
| "imports": { | ||
| "app_one": "http://localhost:3001/remoteEntry.js", | ||
| "app_two": "http://localhost:3002/remoteEntry.js", | ||
| "app_three": "http://localhost:3003/remoteEntry.js", | ||
| "app_one/": "http://localhost:3001/", | ||
| "app_two/": "http://localhost:3002/", | ||
| "app_three/": "http://localhost:3003/" | ||
| } | ||
| } | ||
| </script> | ||
| </head> | ||
| <body> | ||
| <div id="root"></div> | ||
| <script src="https://unpkg.com/systemjs/dist/system.js"></script> | ||
| <script> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't you also need to call |
||
| System.import('app_one/main.js') | ||
| </script> | ||
| </body> | ||
| </html> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "headers": [ | ||
| { | ||
| "source": "**/*", | ||
| "headers": [ | ||
| { | ||
| "key": "Access-Control-Allow-Origin", | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cors is needed for dynamically injected scripts from systemjs |
||
| "value": "*" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| const HtmlWebpackPlugin = require("html-webpack-plugin"); | ||
| const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin"); | ||
| const CopyPlugin = require('copy-webpack-plugin'); | ||
|
|
||
| module.exports = { | ||
| entry: "./src/index", | ||
|
|
@@ -13,7 +13,8 @@ module.exports = { | |
| }, | ||
|
|
||
| output: { | ||
| publicPath: "http://localhost:3001/" | ||
| publicPath: "http://localhost:3001/", | ||
| libraryTarget: "system" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Compiles code to |
||
| }, | ||
|
|
||
| resolve: { | ||
|
|
@@ -28,14 +29,19 @@ module.exports = { | |
| options: { | ||
| presets: [require.resolve("@babel/preset-react")] | ||
| } | ||
| }, | ||
| { | ||
| parser: { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this section needed? |
||
| system: false | ||
| } | ||
| } | ||
| ] | ||
| ], | ||
| }, | ||
|
|
||
| plugins: [ | ||
| new ModuleFederationPlugin({ | ||
| name: "app_one", | ||
| library: { type: "var", name: "app_one" }, | ||
| library: { type: "system" }, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, silly me. removing the name removes the named portion of the module. that makes sense.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah haha I ran into the same problem with the named register but then found this way of removing the name |
||
| filename: "remoteEntry.js", | ||
| remotes: { | ||
| app_two: "app_two", | ||
|
|
@@ -46,8 +52,8 @@ module.exports = { | |
| }, | ||
| shared: ["react", "react-dom","react-router-dom"] | ||
| }), | ||
| new HtmlWebpackPlugin({ | ||
| template: "./public/index.html" | ||
| }) | ||
| new CopyPlugin([ | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using the copy plugin to ensure serve.json is in the dist directory (so that cors works) |
||
| { from: 'public', to: '.' } | ||
| ]) | ||
| ] | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,6 @@ | |
| "scripts": { | ||
| "start": "webpack --watch", | ||
| "build": "webpack --mode production", | ||
| "serve": "serve dist -p 3002" | ||
| "serve": "serve dist -p 3002 -s" | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,24 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <script src="http://localhost:3001/remoteEntry.js"></script> | ||
| <script type="systemjs-importmap"> | ||
| { | ||
| "imports": { | ||
| "app_one": "http://localhost:3001/remoteEntry.js", | ||
| "app_two": "http://localhost:3002/remoteEntry.js", | ||
| "app_three": "http://localhost:3003/remoteEntry.js", | ||
| "app_one/": "http://localhost:3001/", | ||
| "app_two/": "http://localhost:3002/", | ||
| "app_three/": "http://localhost:3003/" | ||
| } | ||
| } | ||
| </script> | ||
| </head> | ||
| <body> | ||
| <div id="root"></div> | ||
| <script src="https://unpkg.com/systemjs/dist/system.js"></script> | ||
| <script> | ||
| System.import('app_two/main.js') | ||
| </script> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "headers": [ | ||
| { | ||
| "source": "**/*", | ||
| "headers": [ | ||
| { | ||
| "key": "Access-Control-Allow-Origin", | ||
| "value": "*" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| const HtmlWebpackPlugin = require("html-webpack-plugin"); | ||
| const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin"); | ||
| const CopyPlugin = require('copy-webpack-plugin'); | ||
|
|
||
| module.exports = { | ||
| entry: "./src/index", | ||
|
|
@@ -13,7 +13,8 @@ module.exports = { | |
| }, | ||
|
|
||
| output: { | ||
| publicPath: "http://localhost:3002/" | ||
| publicPath: "http://localhost:3002/", | ||
| libraryTarget: "system" | ||
| }, | ||
|
|
||
| resolve: { | ||
|
|
@@ -35,7 +36,7 @@ module.exports = { | |
| plugins: [ | ||
| new ModuleFederationPlugin({ | ||
| name: "app_two", | ||
| library: { type: "var", name: "app_two" }, | ||
| library: { type: "system" }, | ||
| filename: "remoteEntry.js", | ||
| exposes: { | ||
| Dialog: "./src/Dialog" | ||
|
|
@@ -45,9 +46,8 @@ module.exports = { | |
| }, | ||
| shared: ["react", "react-dom","react-router-dom"] | ||
| }), | ||
| new HtmlWebpackPlugin({ | ||
| template: "./public/index.html", | ||
| chunks: ["main"] | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to inject any scripts into html file anymore |
||
| }) | ||
| new CopyPlugin([ | ||
| { from: 'public', to: '.' } | ||
| ]) | ||
| ] | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,24 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <script type="systemjs-importmap"> | ||
| { | ||
| "imports": { | ||
| "app_one": "http://localhost:3001/remoteEntry.js", | ||
| "app_two": "http://localhost:3002/remoteEntry.js", | ||
| "app_three": "http://localhost:3003/remoteEntry.js", | ||
| "app_one/": "http://localhost:3001/", | ||
| "app_two/": "http://localhost:3002/", | ||
| "app_three/": "http://localhost:3003/" | ||
| } | ||
| } | ||
| </script> | ||
| </head> | ||
| <body> | ||
| <div id="root"></div> | ||
| <script src="https://unpkg.com/systemjs/dist/system.js"></script> | ||
| <script> | ||
| System.import('app_three/main.js') | ||
| </script> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "headers": [ | ||
| { | ||
| "source": "**/*", | ||
| "headers": [ | ||
| { | ||
| "key": "Access-Control-Allow-Origin", | ||
| "value": "*" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The import map
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we need an org name here in the app names
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
org names are a best practice but are not required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, just wondering