-
-
Notifications
You must be signed in to change notification settings - Fork 375
feat: add shareStrategy option #2870
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
Changes from all commits
d28d4af
2a06542
d9b2c37
7013a70
b599f92
f43adb6
5a9436e
0d7692c
d6c4b9a
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 |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| '@module-federation/enhanced': patch | ||
| '@module-federation/runtime': patch | ||
| '@module-federation/sdk': patch | ||
| --- | ||
|
|
||
| feat: add shareStrategy option |
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # shareStrategy | ||
|
|
||
| - Type: `'version-first' | 'loaded-first'` | ||
| - Required: No | ||
| - Default: `'version-first'` | ||
|
|
||
| Control the loading strategy of shared dependencies: | ||
|
|
||
| - `'version-first'`: Version priority, ensuring that the highest version of shared dependencies is used. After setting, all *remotes* entry files will be automatically loaded and **register** the corresponding shared dependencies to ensure that all shared dependency versions can be obtained. This strategy is recommended when there are strict version requirements. | ||
|
|
||
| - `'loaded-first'`: Prioritize reuse, greatly reducing redundant dependency requests. After setting, the *remotes* entry file will not be automatically loaded (it will only be loaded when needed), and the loaded shared dependencies will be reused first. This strategy is recommended when there are no strict requirements on the version and performance is required. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # shareStrategy | ||
|
|
||
| - 类型:`'version-first' | 'loaded-first'` | ||
| - 是否必填:否 | ||
| - 默认值:`'version-first'` | ||
|
|
||
| 控制共享依赖的加载策略: | ||
|
|
||
| - `'version-first'`:版本优先,确保使用最高版本的共享依赖。设置后,会自动加载所有 *remotes* 入口文件,并**注册**对应的共享依赖,确保能获取到所有的共享依赖版本。当对版本有严格要求时,推荐使用此策略。 | ||
|
|
||
| - `'loaded-first'`:复用优先,大幅减少多余的依赖请求。设置后,不会自动加载 *remotes* 入口文件(仅在有需求时才会加载),优先复用已加载的共享依赖。当对版本没有严格要求且对性能有要求时,推荐使用此策略。 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -410,6 +410,10 @@ export default { | |
| ], | ||
| }, | ||
| }, | ||
| ShareStrategy: { | ||
| description: "Load shared strategy(defaults to 'version-first').", | ||
| enum: ['version-first', 'loaded-first'], | ||
2heal1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| Shared: { | ||
| description: | ||
| 'Modules that should be shared in the share scope. When provided, property names are used to match requested modules in this compilation.', | ||
|
|
@@ -463,6 +467,9 @@ export default { | |
| type: 'string', | ||
| minLength: 1, | ||
| }, | ||
| shareStrategy: { | ||
| $ref: '#/definitions/ShareStrategy', | ||
|
Comment on lines
+470
to
+471
Contributor
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. The For example, you could create a separate |
||
| }, | ||
| requiredVersion: { | ||
| description: 'Version requirement from module in share scope.', | ||
| anyOf: [ | ||
|
|
@@ -762,6 +769,9 @@ export default { | |
| type: 'string', | ||
| minLength: 1, | ||
| }, | ||
| shareStrategy: { | ||
| $ref: '#/definitions/ShareStrategy', | ||
| }, | ||
2heal1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| shared: { | ||
| $ref: '#/definitions/Shared', | ||
| }, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import React from 'react'; | ||
|
|
||
| export default () => { | ||
| return `App rendered with [${React()}]`; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| it('should load the component from container', () => { | ||
| return import('./App').then(({ default: App }) => { | ||
| expect(App()).toBe('App rendered with [This is react 0.1.2]'); | ||
|
|
||
| const shareStrategy = | ||
| __webpack_require__.federation.initOptions.shareStrategy; | ||
| // name: "react", version: "0.1.2", eager: 0, singleton: 1, requiredVersion: "*", strictVersion: 0 | ||
| expect(shareStrategy).toBe('version-first'); | ||
| }); | ||
| }); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "name": "shared-strategy" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| const { SharePlugin } = require('../../../../dist/src'); | ||
|
|
||
| module.exports = { | ||
| mode: 'development', | ||
| devtool: false, | ||
| plugins: [ | ||
| new SharePlugin({ | ||
| name: 'shared-strategy', | ||
| shared: { | ||
| react: { | ||
| requiredVersion: false, | ||
| singleton: true, | ||
| strictVersion: false, | ||
| version: '0.1.2', | ||
| }, | ||
| }, | ||
| }), | ||
| ], | ||
| }; |
Uh oh!
There was an error while loading. Please reload this page.