Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.

Commit d3f6835

Browse files
committed
pre1.0.0
1 parent d36b81e commit d3f6835

File tree

2 files changed

+34
-48
lines changed

2 files changed

+34
-48
lines changed

packages/universal-module-federation-plugin/README-cn.md

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ module.exports = {
3838
filename: 'remoteEntry.js',
3939
remotes: {
4040
app2: "app2@http://localhost:9002/remoteEntry.js",
41-
"react-router": "app4reactRouter@https://unpkg.com/react-router@6.4.3/dist/umd/react-router.production.min.js",
42-
"@remix-run/router": "app5remixRouter@https://unpkg.com/@remix-run/router@1.0.3/dist/router.umd.min.js"
4341
},
4442
exposes: {
4543
'./App': './src/App',
@@ -48,7 +46,10 @@ module.exports = {
4846
}),
4947
new UmdPlugin({
5048
// 匹配的remote以umd模式加载
51-
includeRemotes: [/react-router/, "@remix-run/router"],
49+
remotes: {
50+
"react-router": "app4reactRouter@https://unpkg.com/react-router@6.4.3/dist/umd/react-router.production.min.js",
51+
"@remix-run/router": "app5remixRouter@https://unpkg.com/@remix-run/router@1.0.3/dist/router.umd.min.js"
52+
},
5253
dependencies: {
5354
automatic: ["shareScopes", "remotes"],
5455
}
@@ -65,10 +66,9 @@ module.exports = {
6566

6667
| options | desc | default | examles |
6768
|-------------------------------|--------------------------------------------|-----------------------------------|:--------------------------------------------------|
68-
| includeRemotes | 匹配 umd remote | [] | [/umd-app/, "app3"] |
69-
| excludeRemotes | 排除 umd remotes | [] | ["app2"] |
69+
| remotes | umd remotes | {} | {app2: "app@http://xxx.js"} |
7070
| dependencies.automatic | 自动匹配remotes和shared中同名的依赖项 | ["shareScopes", "remotes"] | |
71-
| dependencies.referenceShares | 配置从 __*shared*__ 中寻找umd的依赖 | {} | {react: {singleton: true, requiredVersion: "17"}} |
71+
| dependencies.referenceShares | 配置从 __*shared*__ 中寻找umd的依赖 | {} | {react: {singleton: true, requiredVersion: "17"}} |
7272
| dependencies.referenceRemotes | 配置从remotes中寻找umd的依赖 | {} | {react: "app5"} |
7373
| runtimeUmdExposes | 如果umd包有多个入口,可以用这个函数解析入口 | ({$umdValue}) => return $umdValue | |
7474
| runtimeInject |__*UniversalModuleFederationPlugin*__ | | |
@@ -98,8 +98,7 @@ const {UniversalModuleFederationPlugin} = require("universal-module-federation-p
9898

9999
plugins: [
100100
new UniversalModuleFederationPlugin({
101-
includeRemotes: [/.*/],
102-
excludeRemotes: [],
101+
remotes: {},
103102
runtimeInject: {
104103
injectVars: {},
105104
initial: () => {},
@@ -115,8 +114,7 @@ plugins: [
115114
// webpack.config.js
116115
plugins: [
117116
new UniversalModuleFederationPlugin({
118-
includeRemotes: [/.*/],
119-
excludeRemotes: [],
117+
remotes: {},
120118
runtimeInject: {
121119
// 可以在以下任何runtime hooks中访问"__umf__.$injectVars.testInjectVar"
122120
injectVars: {
@@ -158,14 +156,13 @@ plugins: [
158156

159157
## UniversalModuleFederationPlugin API
160158

161-
| options | desc | default | examles |
162-
|----------------------------------------------|--------------------------------------------------------------------------------------------|--------------|:--------------------|
163-
| includeRemotes | 匹配 umf remotes | [] | [/umf-app/, "app3"] |
164-
| excludeRemotes | 排除 umf remotes | [] | ["app2"] |
165-
| runtimeInject.injectVars | 为runtime hooks注入变量,任何运行时挂钩都可以使用"\_\_umf\_\_.$injectVars"访问 | {} | {test: 123} |
166-
| runtimeInject.initial():promise | 初始化阶段的runtime hook | function(){} | |
167-
| runtimeInject.beforeImport(url, options):promise<url> | 准备引入remote时触发 | function(){} | |
168-
| runtimeInject.import(url, options):promise<module> | remote的引入钩子, 需要返回一个 container{init, get} | function(){} |
159+
| options | desc | default | examles |
160+
|-------------------------------------------------------|-------------------------------------------------------------------------------|--------------|:----------------------------|
161+
| remotes | umf remotes | {} | {app2: "app@http://xxx.js"} |
162+
| runtimeInject.injectVars | 为runtime hooks注入变量,任何运行时挂钩都可以使用"\_\_umf\_\_.$injectVars"访问 | {} | {test: 123} |
163+
| runtimeInject.initial():promise | 初始化阶段的runtime hook | function(){} | |
164+
| runtimeInject.beforeImport(url, options):promise<url> | 准备引入remote时触发 | function(){} | |
165+
| runtimeInject.import(url, options):promise<module> | remote的引入钩子, 需要返回一个 container{init, get} | function(){} | |
169166

170167
#### \_\_umf\_\_
171168

@@ -192,17 +189,15 @@ const {UniversalModuleFederationPlugin} = require("universal-module-federation-p
192189
module.exports = {
193190
plugins: [
194191
new ModuleFederationPlugin({
195-
// ...,
192+
shared: { react: { singleton: true } },
193+
}),
194+
new UniversalModuleFederationPlugin({
196195
remotes: {
197196
// 1: {name}@{url}
198197
// 2: {name}@{dynamic semver remote}
199198
app2: "app2@http://localhost:3000/remoteEntry.js",
200199
"mf-app-01": "mfapp01@mf-app-01@1.0.2/dist/remoteEntry.js"
201200
},
202-
shared: { react: { singleton: true } },
203-
}),
204-
new UniversalModuleFederationPlugin({
205-
includeRemotes: [/./],
206201
runtimeInject: {
207202
resolvePath({name, version, entry, query}) {
208203
return `https://cdn.jsdelivr.net/npm/${name}@${version}/${entry}?${query}`

packages/universal-module-federation-plugin/README.md

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ module.exports = {
3939
filename: 'remoteEntry.js',
4040
remotes: {
4141
app2: "app2@http://localhost:9002/remoteEntry.js",
42-
"react-router": "app4reactRouter@https://unpkg.com/react-router@6.4.3/dist/umd/react-router.production.min.js",
43-
"@remix-run/router": "app5remixRouter@https://unpkg.com/@remix-run/router@1.0.3/dist/router.umd.min.js"
4442
},
4543
exposes: {
4644
'./App': './src/App',
@@ -49,9 +47,9 @@ module.exports = {
4947
}),
5048
new UmdPlugin({
5149
// The matched remotes are loaded in umd mode
52-
includeRemotes: [/react-router/, "@remix-run/router"],
53-
dependencies: {
54-
automatic: ["shareScopes", "remotes"],
50+
remotes: {
51+
"react-router": "app4reactRouter@https://unpkg.com/react-router@6.4.3/dist/umd/react-router.production.min.js",
52+
"@remix-run/router": "app5remixRouter@https://unpkg.com/@remix-run/router@1.0.3/dist/router.umd.min.js"
5553
}
5654
}),
5755
new UmdPlugin({
@@ -66,8 +64,7 @@ module.exports = {
6664

6765
| options | desc | interface | default | examles |
6866
|-------------------------------|-------------------------------------------------------------------------------------------|:-----------------------------------------------|-----------------------------------|:--------------------------------------------------|
69-
| includeRemotes | match umd remotes | Array<RegExp \| string> | string> | string> |
70-
| excludeRemotes | exclude umd remotes | Array<RegExp \| string> | string> | string> |
67+
| remotes | umd remotes | { remoteKey: "{global}@{url}" } | {} | string> |
7168
| dependencies.automatic | Automatically match dependencies with the same name in remotes and shared | enum array | ["shareScopes", "remotes"] | |
7269
| dependencies.referenceShares | umd dependencies use by shares | refer to __*shared*__ config | {} | {react: {singleton: true, requiredVersion: "17"}} |
7370
| dependencies.referenceRemotes | umd dependencies use by remotes | Map<string, string> | {} | {react: "app5"} |
@@ -100,12 +97,10 @@ const {UniversalModuleFederationPlugin} = require("universal-module-federation-p
10097

10198
plugins: [
10299
new UniversalModuleFederationPlugin({
103-
includeRemotes: [/.*/],
104-
excludeRemotes: [],
100+
remotes: {},
105101
runtimeInject: {
106102
injectVars: {},
107103
initial: () => {},
108-
beforeImport(url, options) {},
109104
import(url, options) {}
110105
}
111106
})
@@ -117,8 +112,7 @@ plugins: [
117112
// webpack.config.js
118113
plugins: [
119114
new UniversalModuleFederationPlugin({
120-
includeRemotes: [/.*/],
121-
excludeRemotes: [],
115+
remotes: { app2: "app2@http://xxx.js" },
122116
runtimeInject: {
123117
// You can access "__umf__.$injectVars.testInjectVar" in any of the following runtime hooks
124118
injectVars: {
@@ -160,14 +154,13 @@ plugins: [
160154

161155
## UniversalModuleFederationPlugin API
162156

163-
| options | desc | default | examles |
164-
|----------------------------------------------|------------------------------------------------------------------------------------------------|---------|:--------------------|
165-
| includeRemotes | match umf remotes | [] | [/umf-app/, "app3"] |
166-
| excludeRemotes | exclude umf remotes | [] | ["app2"] |
167-
| runtimeInject.injectVars | Inject variables for other runtime hooks, any runtime hook can using "\_\_umf\_\_.$injectVars" | {} | {test: 123} |
168-
| runtimeInject.initial():promise | initial runtime hooks | [] | |
169-
| runtimeInject.beforeImport(url, options):promise<url> | Triggered before each remote is introduced | [] | |
170-
| runtimeInject.import(url, options):promise<module> | Introduce the hook of remote, need to return a container{init, get} | [] | |
157+
| options | desc | default | examles |
158+
|-------------------------------------------------------|------------------------------------------------------------------------------------------------|----------------------------------|:---------------------------|
159+
| remotes | umf remotes | { remoteKey: "{global}@{url}" } | {app2: "app@http://xx.js"} |
160+
| runtimeInject.injectVars | Inject variables for other runtime hooks, any runtime hook can using "\_\_umf\_\_.$injectVars" | {} | {test: 123} |
161+
| runtimeInject.initial():promise | initial runtime hooks | [] | |
162+
| runtimeInject.beforeImport(url, options):promise<url> | Triggered before each remote is introduced | [] | |
163+
| runtimeInject.import(url, options):promise<module> | Introduce the hook of remote, need to return a container{init, get} | [] | |
171164

172165
#### \_\_umf\_\_
173166

@@ -195,17 +188,15 @@ const {UniversalModuleFederationPlugin} = require("universal-module-federation-p
195188
module.exports = {
196189
plugins: [
197190
new ModuleFederationPlugin({
198-
// ...,
191+
shared: { react: { singleton: true } },
192+
}),
193+
new UniversalModuleFederationPlugin({
199194
remotes: {
200195
// 1: {name}@{url}
201196
// 2: {name}@{dynamic semver remote}
202197
app2: "app2@http://localhost:3000/remoteEntry.js",
203198
"mf-app-01": "mfapp01@mf-app-01@1.0.2/dist/remoteEntry.js"
204199
},
205-
shared: { react: { singleton: true } },
206-
}),
207-
new UniversalModuleFederationPlugin({
208-
includeRemotes: [/./],
209200
runtimeInject: {
210201
resolvePath({name, version, entry, query}) {
211202
return `https://cdn.jsdelivr.net/npm/${name}@${version}/${entry}?${query}`

0 commit comments

Comments
 (0)