Skip to content

Commit

Permalink
fix(example): update example and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
unadlib committed Oct 30, 2024
1 parent f9dfbe7 commit 5ca3d32
Show file tree
Hide file tree
Showing 5 changed files with 247 additions and 4 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ const App2 = useApp({

4. You can bootstrap `app1` and `app2` projects with RC MFE.

## Usage in SharedWorker

1. Use SharedWorker in host application with `getWorkerName`
2. Dynamically import bootstrap file in worker thread
3. Add another entry points with `target: 'webworker'` and set `output.publicPath` and `output.path` in MFE webpack config(e.g. `examples/basic/app3/webpack.config.js`).

> `webpack dev server` is not supported in multiple entry points, so you need to build and serve the worker file manually(e.g. `examples/basic/app3/dev.js`).
## Contribution

> Note: `packages/builder/src/make.ts` and `packages/shared/src/*`
Expand Down
26 changes: 26 additions & 0 deletions examples/basic/app3/dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const express = require('express');
const webpack = require('webpack');
const webpackDevMiddleware = require('webpack-dev-middleware');

const app = express();
const [config1, config2] = require('./webpack.config');

const compiler1 = webpack(config1);
const compiler2 = webpack(config2);

app.use(
webpackDevMiddleware(compiler1, {
publicPath: config1.output.publicPath,
})
);

app.use(
webpackDevMiddleware(compiler2, {
publicPath: `${config2.output.publicPath}worker/`,
})
);

app.listen(3003, () => {
console.log('App3 listening on port 3003!\n');
});
4 changes: 3 additions & 1 deletion examples/basic/app3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
"@types/react-dom": "^17.0.18",
"@types/react-router-dom": "^5.3.3",
"babel-loader": "^9.1.0",
"express": "^4.21.1",
"html-webpack-plugin": "^5.5.0",
"serve": "^14.1.1",
"webpack": "^5.90.1",
"webpack-cli": "^4.10.0",
"webpack-dev-middleware": "^7.4.2",
"webpack-dev-server": "^4.11.1"
},
"scripts": {
"start": "webpack-cli serve",
"start": "node ./dev.js",
"build": "webpack --mode production",
"serve": "serve dist -p 3003 --cors",
"clean": "rm -rf dist"
Expand Down
Loading

0 comments on commit 5ca3d32

Please sign in to comment.