Skip to content

Commit 6259e94

Browse files
committed
feat: support wp5
1 parent 38579fe commit 6259e94

File tree

2 files changed

+89
-2
lines changed

2 files changed

+89
-2
lines changed

README.md

+67-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22

33
Use `single-spa` `systemjs` in your `create-react-app`.
44

5-
> Quickly adapt cra as a submodule of single-spa !!!
5+
> Quickly adapt `react-scripts` as a submodule of single-spa !!!
6+
> Support `[email protected]` `[email protected]` version.
7+
8+
## Features
9+
10+
- Support `[email protected]` compatible with common configuration migrations
11+
- Output `systemjs` library auto add `SystemJSPublicPathPlugin`
12+
- Support `ReactFastRefresh` hot refresh
613

714
## Installation
815

@@ -35,11 +42,69 @@ module.exports = {
3542
const { override, overrideDevServer } = require("customize-cra");
3643

3744
module.exports = {
38-
webpack: override(rewiredSingleSpa()),
45+
webpack: override(
46+
rewiredSingleSpa({
47+
orgName: "you",
48+
projectName: "test",
49+
reactPackagesAsExternal: true,
50+
peerDepsAsExternal: true,
51+
orgPackagesAsExternal: true,
52+
})
53+
),
3954
devServer: overrideDevServer(rewiredSingleSpaDevServer()),
4055
};
4156
```
4257

58+
## Options
59+
60+
### orgName
61+
Type: `string`
62+
The name of the organization this application is written for.
63+
64+
### projectName
65+
Type: `string`
66+
The name of the current project. This usually matches the git repo's name.
67+
68+
### entry
69+
Type: `string`
70+
Default: `src/{orgName}-{projectName}.{js|jsx|ts|tsx}` `src/index.{js|jsx|ts|tsx}`
71+
The entry file.
72+
73+
### outputFilename
74+
Type: `string`
75+
Default:
76+
- development `{orgName}-{projectName}.[contenthash:8].js`
77+
- production `{orgName}-{projectName}.js`
78+
79+
### rootDirectoryLevel
80+
Type: `number`
81+
This is the rootDirectoryLevel that is passed to https://github.com/joeldenning/systemjs-webpack-interop.
82+
83+
### reactPackagesAsExternal
84+
Type: `boolean`
85+
This will `react` `react-dom` as webpack externals or not.
86+
87+
### orgPackagesAsExternal
88+
Type: `boolean`
89+
This changes whether package names that start with @your-org-name are treated as webpack externals or not.
90+
91+
### peerDepsAsExternal
92+
Type: `boolean`
93+
This will package.json `peerDependencies` as webpack externals or not.
94+
95+
## FQA
96+
97+
### FastRefresh invalid
98+
- If `react` `react-dom` is external, `react-dev-tool` must be installed to refresh automatically.
99+
For details, please see https://github.com/facebook/react/issues/17552
100+
- Check whether the ws connection is normal, you can set in `.env` file
101+
- `WDS_SOCKET_PORT` "2002"
102+
- `WDS_SOCKET_HOST` "localhost"
103+
- `WDS_SOCKET_PATH` "/projectName" **Please start with "/"**
104+
> The default hotreload client uses the relative website protocol,
105+
which is the protocol of the main base. It can use the localhost
106+
protocol and the local development port.
107+
43108
## License
44109

45110
MIT © [fupengl](https://github.com/fupengl)

index.js

+22
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,28 @@ function rewiredSingleSpa({
150150

151151
disableCSSExtraction(config);
152152

153+
// for wp5
154+
// https://stackoverflow.com/questions/64557638/how-to-polyfill-node-core-modules-in-webpack-5
155+
if (webpackMajorVersion == 5) {
156+
config.plugins.push(
157+
new webpack.ProvidePlugin({
158+
process: "process/browser.js",
159+
Buffer: ["buffer", "Buffer"],
160+
})
161+
);
162+
config.resolve.fallback = Object.assign(config.resolve.fallback || {}, {
163+
url: require.resolve("url"),
164+
fs: require.resolve("fs"),
165+
assert: require.resolve("assert"),
166+
crypto: require.resolve("crypto-browserify"),
167+
http: require.resolve("stream-http"),
168+
https: require.resolve("https-browserify"),
169+
os: require.resolve("os-browserify/browser"),
170+
buffer: require.resolve("buffer"),
171+
stream: require.resolve("stream-browserify"),
172+
});
173+
}
174+
153175
return config;
154176
};
155177
}

0 commit comments

Comments
 (0)