Skip to content

Commit eb0500d

Browse files
authored
fix(rollup-federation-demo): created single point to start (#2708)
1 parent 1f50614 commit eb0500d

File tree

14 files changed

+51
-31
lines changed

14 files changed

+51
-31
lines changed

rollup-federation-demo/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ This example demos consumption of federated modules from a Rollup bundle. `rollu
66

77
# Running Demo
88

9-
Run `yarn start`. This will build and serve both `webpack-spa` and `rollup-spa` on ports 8081 and 8082 respectively.
9+
Run `yarn install` this will install dependencies for all 3 apps and root.
10+
Run `yarn start`. This will build and serve all three `webpack-spa`, `rollup-spa` and `rs-sidecar` on ports 8081, 8082, 8080 respectively.
1011

12+
- SIDECAR (rollup-spa): [localhost:8080](http://localhost:8080/)
1113
- REMOTE (webpack-spa): [localhost:8081](http://localhost:8081/)
1214
- HOST (rollup-spa): [localhost:8082](http://localhost:8082/)

rollup-federation-demo/package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"private": true,
3+
"workspaces": {
4+
"packages": [
5+
"./rollup-spa",
6+
"./rs-sidecar",
7+
"./webpack-spa"
8+
]
9+
},
10+
"scripts": {
11+
"start": "concurrently 'yarn --cwd rollup-spa start' 'yarn --cwd rs-sidecar start;' 'yarn --cwd webpack-spa start'"
12+
},
13+
"devDependencies": {
14+
"concurrently": "7.3.0"
15+
}
16+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vendor

rollup-federation-demo/rollup-spa/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
<script type="systemjs-importmap">
1616
{
1717
"imports": {
18-
"react": "./node_modules/react/umd/react.production.min.js",
19-
"react-dom": "./node_modules/react-dom/umd/react-dom.production.min.js",
18+
"react": "./vendor/react.production.min.js",
19+
"react-dom": "./vendor/react-dom.production.min.js",
2020
"rwebpackremote": "http://localhost:8081/remoteEntry.js",
2121
"rollup_spa": "http://localhost:8080/remoteEntry.js",
2222
"main": "./dist/index.js"

rollup-federation-demo/rollup-spa/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"npm-run-all": "4.1.5",
2626
"rollup": "2.79.0",
2727
"rollup-plugin-babel": "4.4.0",
28+
"rollup-plugin-copy": "3.4.0",
2829
"rollup-plugin-inject-process-env": "1.3.1",
2930
"serve": "13.0.4"
3031
}

rollup-federation-demo/rollup-spa/rollup.config.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import commonjs from '@rollup/plugin-commonjs';
33
import resolve from '@rollup/plugin-node-resolve';
44
import injectProcessEnv from 'rollup-plugin-inject-process-env';
55
import federation from '@module-federation/rollup-federation';
6+
import copy from 'rollup-plugin-copy'
67

78
import pkg from './package.json';
89

@@ -23,23 +24,29 @@ export default {
2324
}),
2425
commonjs({
2526
transformMixedEsModules: true,
26-
include: ['node_modules/*'],
27+
include: ['node_modules/*', '../node_modules/*'],
2728
}),
2829
babel(),
30+
// This hack is required to have rollup inside yarn worskpaces since it can't properly resolve dependencies from
31+
// parent folder.
32+
copy({
33+
targets: [
34+
{src: [
35+
'../node_modules/react/umd/react.development.js',
36+
'../node_modules/react/umd/react.production.min.js',
37+
'../node_modules/react-dom/umd/react-dom.development.js',
38+
'../node_modules/react-dom/umd/react-dom.production.min.js'
39+
],
40+
dest: 'vendor'
41+
}
42+
]
43+
}),
2944
federation({
3045
remotes: {
3146
foo_app1: 'rwebpackremote',
3247
foo_rollup_spa: 'rollup_spa',
3348
},
3449
shared: {
35-
react: {
36-
singleton: true,
37-
requiredVersion: pkg.dependencies.react,
38-
},
39-
'react-dom': {
40-
singleton: true,
41-
requiredVersion: pkg.dependencies['react-dom'],
42-
},
4350
},
4451
}),
4552
],

0 commit comments

Comments
 (0)