@module-federation/enhanced 0.22.1 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +1 -1
- package/dist/src/declarations/plugins/sharing/ConsumeSharedModule.d.ts +4 -0
- package/dist/src/declarations/plugins/sharing/ConsumeSharedPlugin.d.ts +4 -0
- package/dist/src/declarations/plugins/sharing/ProvideSharedPlugin.d.ts +5 -1
- package/dist/src/declarations/plugins/sharing/SharePlugin.d.ts +8 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +3 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib/container/ContainerPlugin.js +8 -10
- package/dist/src/lib/container/ContainerPlugin.js.map +1 -1
- package/dist/src/lib/container/ContainerReferencePlugin.d.ts +1 -1
- package/dist/src/lib/container/ContainerReferencePlugin.js +10 -9
- package/dist/src/lib/container/ContainerReferencePlugin.js.map +1 -1
- package/dist/src/lib/container/ModuleFederationPlugin.js +28 -18
- package/dist/src/lib/container/ModuleFederationPlugin.js.map +1 -1
- package/dist/src/lib/container/runtime/FederationRuntimePlugin.d.ts +1 -1
- package/dist/src/lib/container/runtime/FederationRuntimePlugin.js +25 -7
- package/dist/src/lib/container/runtime/FederationRuntimePlugin.js.map +1 -1
- package/dist/src/lib/sharing/ConsumeSharedPlugin.js +3 -0
- package/dist/src/lib/sharing/ConsumeSharedPlugin.js.map +1 -1
- package/dist/src/lib/sharing/ConsumeSharedRuntimeModule.js +6 -4
- package/dist/src/lib/sharing/ConsumeSharedRuntimeModule.js.map +1 -1
- package/dist/src/lib/sharing/ProvideSharedDependency.d.ts +2 -1
- package/dist/src/lib/sharing/ProvideSharedDependency.js +6 -4
- package/dist/src/lib/sharing/ProvideSharedDependency.js.map +1 -1
- package/dist/src/lib/sharing/ProvideSharedModule.d.ts +2 -1
- package/dist/src/lib/sharing/ProvideSharedModule.js +7 -4
- package/dist/src/lib/sharing/ProvideSharedModule.js.map +1 -1
- package/dist/src/lib/sharing/ProvideSharedModuleFactory.js +3 -3
- package/dist/src/lib/sharing/ProvideSharedModuleFactory.js.map +1 -1
- package/dist/src/lib/sharing/ProvideSharedPlugin.js +5 -3
- package/dist/src/lib/sharing/ProvideSharedPlugin.js.map +1 -1
- package/dist/src/lib/sharing/SharePlugin.d.ts +41 -2
- package/dist/src/lib/sharing/SharePlugin.js +65 -51
- package/dist/src/lib/sharing/SharePlugin.js.map +1 -1
- package/dist/src/lib/sharing/ShareRuntimeModule.js +4 -3
- package/dist/src/lib/sharing/ShareRuntimeModule.js.map +1 -1
- package/dist/src/lib/sharing/tree-shaking/CollectSharedEntryPlugin.d.ts +18 -0
- package/dist/src/lib/sharing/tree-shaking/CollectSharedEntryPlugin.js +132 -0
- package/dist/src/lib/sharing/tree-shaking/CollectSharedEntryPlugin.js.map +1 -0
- package/dist/src/lib/sharing/tree-shaking/IndependentSharedPlugin.d.ts +36 -0
- package/dist/src/lib/sharing/tree-shaking/IndependentSharedPlugin.js +328 -0
- package/dist/src/lib/sharing/tree-shaking/IndependentSharedPlugin.js.map +1 -0
- package/dist/src/lib/sharing/tree-shaking/IndependentSharedRuntimeModule.d.ts +21 -0
- package/dist/src/lib/sharing/tree-shaking/IndependentSharedRuntimeModule.js +30 -0
- package/dist/src/lib/sharing/tree-shaking/IndependentSharedRuntimeModule.js.map +1 -0
- package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedContainerPlugin.d.ts +28 -0
- package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedContainerPlugin.js +98 -0
- package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedContainerPlugin.js.map +1 -0
- package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedDependency.d.ts +26 -0
- package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedDependency.js +45 -0
- package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedDependency.js.map +1 -0
- package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedEntryDependency.d.ts +17 -0
- package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedEntryDependency.js +31 -0
- package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedEntryDependency.js.map +1 -0
- package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedEntryModule.d.ts +79 -0
- package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedEntryModule.js +156 -0
- package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedEntryModule.js.map +1 -0
- package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedEntryModuleFactory.d.ts +11 -0
- package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedEntryModuleFactory.js +27 -0
- package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedEntryModuleFactory.js.map +1 -0
- package/dist/src/lib/sharing/tree-shaking/SharedUsedExportsOptimizerPlugin.d.ts +18 -0
- package/dist/src/lib/sharing/tree-shaking/SharedUsedExportsOptimizerPlugin.js +237 -0
- package/dist/src/lib/sharing/tree-shaking/SharedUsedExportsOptimizerPlugin.js.map +1 -0
- package/dist/src/lib/sharing/tree-shaking/SharedUsedExportsOptimizerRuntimeModule.d.ts +17 -0
- package/dist/src/lib/sharing/tree-shaking/SharedUsedExportsOptimizerRuntimeModule.js +29 -0
- package/dist/src/lib/sharing/tree-shaking/SharedUsedExportsOptimizerRuntimeModule.js.map +1 -0
- package/dist/src/lib/sharing/tree-shaking/TreeShakingSharedPlugin.d.ts +15 -0
- package/dist/src/lib/sharing/tree-shaking/TreeShakingSharedPlugin.js +52 -0
- package/dist/src/lib/sharing/tree-shaking/TreeShakingSharedPlugin.js.map +1 -0
- package/dist/src/lib/sharing/utils.d.ts +1 -0
- package/dist/src/lib/sharing/utils.js +4 -3
- package/dist/src/lib/sharing/utils.js.map +1 -1
- package/dist/src/rspack.d.ts +1 -1
- package/dist/src/rspack.js +2 -1
- package/dist/src/rspack.js.map +1 -1
- package/dist/src/schemas/container/ModuleFederationPlugin.check.js +2321 -1810
- package/dist/src/schemas/container/ModuleFederationPlugin.check.js.map +1 -1
- package/dist/src/schemas/container/ModuleFederationPlugin.d.ts +57 -0
- package/dist/src/schemas/container/ModuleFederationPlugin.js +60 -0
- package/dist/src/schemas/container/ModuleFederationPlugin.js.map +1 -1
- package/dist/src/schemas/sharing/ConsumeSharedPlugin.check.js +41 -12
- package/dist/src/schemas/sharing/ConsumeSharedPlugin.check.js.map +1 -1
- package/dist/src/schemas/sharing/ConsumeSharedPlugin.d.ts +5 -0
- package/dist/src/schemas/sharing/ConsumeSharedPlugin.js +5 -0
- package/dist/src/schemas/sharing/ConsumeSharedPlugin.js.map +1 -1
- package/dist/src/schemas/sharing/ProvideSharedPlugin.check.d.ts +1 -1
- package/dist/src/schemas/sharing/ProvideSharedPlugin.check.js +103 -74
- package/dist/src/schemas/sharing/ProvideSharedPlugin.check.js.map +1 -1
- package/dist/src/schemas/sharing/ProvideSharedPlugin.d.ts +5 -0
- package/dist/src/schemas/sharing/ProvideSharedPlugin.js +5 -0
- package/dist/src/schemas/sharing/ProvideSharedPlugin.js.map +1 -1
- package/dist/src/schemas/sharing/SharePlugin.check.d.ts +1 -1
- package/dist/src/schemas/sharing/SharePlugin.check.js +642 -471
- package/dist/src/schemas/sharing/SharePlugin.check.js.map +1 -1
- package/dist/src/schemas/sharing/SharePlugin.d.ts +37 -0
- package/dist/src/schemas/sharing/SharePlugin.js +40 -0
- package/dist/src/schemas/sharing/SharePlugin.js.map +1 -1
- package/dist/src/wrapper/AsyncBoundaryPlugin.d.ts +2 -5
- package/dist/src/wrapper/AsyncBoundaryPlugin.js +6 -11
- package/dist/src/wrapper/AsyncBoundaryPlugin.js.map +1 -1
- package/dist/src/wrapper/BaseWrapperPlugin.d.ts +27 -0
- package/dist/src/wrapper/BaseWrapperPlugin.js +42 -0
- package/dist/src/wrapper/BaseWrapperPlugin.js.map +1 -0
- package/dist/src/wrapper/ConsumeSharedPlugin.d.ts +2 -5
- package/dist/src/wrapper/ConsumeSharedPlugin.js +6 -11
- package/dist/src/wrapper/ConsumeSharedPlugin.js.map +1 -1
- package/dist/src/wrapper/ContainerPlugin.d.ts +2 -5
- package/dist/src/wrapper/ContainerPlugin.js +6 -11
- package/dist/src/wrapper/ContainerPlugin.js.map +1 -1
- package/dist/src/wrapper/ContainerReferencePlugin.d.ts +2 -5
- package/dist/src/wrapper/ContainerReferencePlugin.js +6 -11
- package/dist/src/wrapper/ContainerReferencePlugin.js.map +1 -1
- package/dist/src/wrapper/FederationModulesPlugin.d.ts +4 -4
- package/dist/src/wrapper/FederationModulesPlugin.js +8 -9
- package/dist/src/wrapper/FederationModulesPlugin.js.map +1 -1
- package/dist/src/wrapper/FederationRuntimePlugin.d.ts +3 -5
- package/dist/src/wrapper/FederationRuntimePlugin.js +8 -10
- package/dist/src/wrapper/FederationRuntimePlugin.js.map +1 -1
- package/dist/src/wrapper/HoistContainerReferencesPlugin.d.ts +2 -4
- package/dist/src/wrapper/HoistContainerReferencesPlugin.js +6 -10
- package/dist/src/wrapper/HoistContainerReferencesPlugin.js.map +1 -1
- package/dist/src/wrapper/ModuleFederationPlugin.d.ts +3 -5
- package/dist/src/wrapper/ModuleFederationPlugin.js +5 -10
- package/dist/src/wrapper/ModuleFederationPlugin.js.map +1 -1
- package/dist/src/wrapper/ProvideSharedPlugin.d.ts +2 -5
- package/dist/src/wrapper/ProvideSharedPlugin.js +6 -11
- package/dist/src/wrapper/ProvideSharedPlugin.js.map +1 -1
- package/dist/src/wrapper/SharePlugin.d.ts +2 -5
- package/dist/src/wrapper/SharePlugin.js +6 -11
- package/dist/src/wrapper/SharePlugin.js.map +1 -1
- package/dist/src/wrapper/TreeShakingSharedPlugin.d.ts +5 -0
- package/dist/src/wrapper/TreeShakingSharedPlugin.js +14 -0
- package/dist/src/wrapper/TreeShakingSharedPlugin.js.map +1 -0
- package/package.json +13 -13
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const normalize_webpack_path_1 = require("@module-federation/sdk/normalize-webpack-path");
|
|
4
|
+
const makeSerializable = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack/lib/util/makeSerializable'));
|
|
5
|
+
const { Dependency } = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack'));
|
|
6
|
+
class SharedEntryDependency extends Dependency {
|
|
7
|
+
/**
|
|
8
|
+
* @param {string} name entry name
|
|
9
|
+
* @param {string} request the request of the entry
|
|
10
|
+
*/
|
|
11
|
+
constructor(name, request) {
|
|
12
|
+
super();
|
|
13
|
+
this.name = name;
|
|
14
|
+
this.request = request;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* @returns {string | null} an identifier to merge equal requests
|
|
18
|
+
*/
|
|
19
|
+
getResourceIdentifier() {
|
|
20
|
+
return `shared-entry-${this.name}`;
|
|
21
|
+
}
|
|
22
|
+
get type() {
|
|
23
|
+
return 'shared entry';
|
|
24
|
+
}
|
|
25
|
+
get category() {
|
|
26
|
+
return 'esm';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
makeSerializable(SharedEntryDependency, 'enhanced/lib/container/SharedEntryDependency');
|
|
30
|
+
exports.default = SharedEntryDependency;
|
|
31
|
+
//# sourceMappingURL=SharedEntryDependency.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SharedEntryDependency.js","sourceRoot":"","sources":["../../../../../../src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedEntryDependency.ts"],"names":[],"mappings":";;AAAA,0FAAqF;AAErF,MAAM,gBAAgB,GAAG,OAAO,CAC9B,IAAA,6CAAoB,EAAC,mCAAmC,CAAC,CAC1D,CAAC;AACF,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAC5B,IAAA,6CAAoB,EAAC,SAAS,CAAC,CACJ,CAAC;AAE9B,MAAM,qBAAsB,SAAQ,UAAU;IAI5C;;;OAGG;IACH,YAAY,IAAY,EAAE,OAAe;QACvC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;OAEG;IACM,qBAAqB;QAC5B,OAAO,gBAAgB,IAAI,CAAC,IAAI,EAAE,CAAC;IACrC,CAAC;IAED,IAAa,IAAI;QACf,OAAO,cAAc,CAAC;IACxB,CAAC;IAED,IAAa,QAAQ;QACnB,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAED,gBAAgB,CACd,qBAAqB,EACrB,8CAA8C,CAC/C,CAAC;AAEF,kBAAe,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { Compilation } from 'webpack';
|
|
2
|
+
import type { CodeGenerationResult, InputFileSystem, LibIdentOptions, NeedBuildContext, ObjectDeserializerContext, ObjectSerializerContext, RequestShortener, ResolverWithOptions, WebpackOptions } from 'webpack/lib/Module';
|
|
3
|
+
import type WebpackError from 'webpack/lib/WebpackError';
|
|
4
|
+
declare const Module: typeof import("webpack").Module;
|
|
5
|
+
export type ExposeOptions = {
|
|
6
|
+
/**
|
|
7
|
+
* requests to exposed modules (last one is exported)
|
|
8
|
+
*/
|
|
9
|
+
import: string[];
|
|
10
|
+
/**
|
|
11
|
+
* custom chunk name for the exposed module
|
|
12
|
+
*/
|
|
13
|
+
name: string;
|
|
14
|
+
};
|
|
15
|
+
declare class SharedEntryModule extends Module {
|
|
16
|
+
private _name;
|
|
17
|
+
private _request;
|
|
18
|
+
/**
|
|
19
|
+
* @param {string} name shared name
|
|
20
|
+
* @param {string} request request
|
|
21
|
+
*/
|
|
22
|
+
constructor(name: string, request: string);
|
|
23
|
+
/**
|
|
24
|
+
* @param {ObjectDeserializerContext} context context
|
|
25
|
+
* @returns {SharedEntryModule} deserialized container entry module
|
|
26
|
+
*/
|
|
27
|
+
static deserialize(context: ObjectDeserializerContext): SharedEntryModule;
|
|
28
|
+
/**
|
|
29
|
+
* @returns {Set<string>} types available (do not mutate)
|
|
30
|
+
*/
|
|
31
|
+
getSourceTypes(): Set<string>;
|
|
32
|
+
/**
|
|
33
|
+
* @returns {string} a unique identifier of the module
|
|
34
|
+
*/
|
|
35
|
+
identifier(): string;
|
|
36
|
+
/**
|
|
37
|
+
* @param {RequestShortener} requestShortener the request shortener
|
|
38
|
+
* @returns {string} a user readable identifier of the module
|
|
39
|
+
*/
|
|
40
|
+
readableIdentifier(requestShortener: RequestShortener): string;
|
|
41
|
+
/**
|
|
42
|
+
* @param {LibIdentOptions} options options
|
|
43
|
+
* @returns {string | null} an identifier for library inclusion
|
|
44
|
+
*/
|
|
45
|
+
libIdent(options: LibIdentOptions): string | null;
|
|
46
|
+
/**
|
|
47
|
+
* @param {NeedBuildContext} context context info
|
|
48
|
+
* @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
|
|
49
|
+
* @returns {void}
|
|
50
|
+
*/
|
|
51
|
+
needBuild(context: NeedBuildContext, callback: (arg0: (WebpackError | null) | undefined, arg1: boolean | undefined) => void): void;
|
|
52
|
+
/**
|
|
53
|
+
* @param {WebpackOptions} options webpack options
|
|
54
|
+
* @param {Compilation} compilation the compilation
|
|
55
|
+
* @param {ResolverWithOptions} resolver the resolver
|
|
56
|
+
* @param {InputFileSystem} fs the file system
|
|
57
|
+
* @param {function(WebpackError): void} callback callback function
|
|
58
|
+
* @returns {void}
|
|
59
|
+
*/
|
|
60
|
+
build(options: WebpackOptions, compilation: Compilation, resolver: ResolverWithOptions, fs: InputFileSystem, callback: (err?: WebpackError) => void): void;
|
|
61
|
+
/**
|
|
62
|
+
* @param {CodeGenerationContext} context context for code generation
|
|
63
|
+
* @returns {CodeGenerationResult} result
|
|
64
|
+
*/
|
|
65
|
+
codeGeneration({ chunkGraph, runtimeTemplate, }: CodeGenerationResult): {
|
|
66
|
+
sources: Map<any, any>;
|
|
67
|
+
runtimeRequirements: Set<"__webpack_require__.d" | "__webpack_require__.o" | "__webpack_exports__">;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* @param {string=} type the source type for which the size should be estimated
|
|
71
|
+
* @returns {number} the estimated size of the module (must be non-zero)
|
|
72
|
+
*/
|
|
73
|
+
size(type?: string): number;
|
|
74
|
+
/**
|
|
75
|
+
* @param {ObjectSerializerContext} context context
|
|
76
|
+
*/
|
|
77
|
+
serialize(context: ObjectSerializerContext): void;
|
|
78
|
+
}
|
|
79
|
+
export default SharedEntryModule;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const normalize_webpack_path_1 = require("@module-federation/sdk/normalize-webpack-path");
|
|
7
|
+
const SharedDependency_1 = __importDefault(require("./SharedDependency"));
|
|
8
|
+
const utils_1 = require("../../../container/runtime/utils");
|
|
9
|
+
const makeSerializable = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack/lib/util/makeSerializable'));
|
|
10
|
+
const { sources: webpackSources, Template, Module, RuntimeGlobals, } = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack'));
|
|
11
|
+
const StaticExportsDependency = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack/lib/dependencies/StaticExportsDependency'));
|
|
12
|
+
const SOURCE_TYPES = new Set(['javascript']);
|
|
13
|
+
class SharedEntryModule extends Module {
|
|
14
|
+
/**
|
|
15
|
+
* @param {string} name shared name
|
|
16
|
+
* @param {string} request request
|
|
17
|
+
*/
|
|
18
|
+
constructor(name, request) {
|
|
19
|
+
super('shared-entry-module', null);
|
|
20
|
+
// super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, null);
|
|
21
|
+
this._name = name;
|
|
22
|
+
this._request = request;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @param {ObjectDeserializerContext} context context
|
|
26
|
+
* @returns {SharedEntryModule} deserialized container entry module
|
|
27
|
+
*/
|
|
28
|
+
static deserialize(context) {
|
|
29
|
+
const { read } = context;
|
|
30
|
+
const obj = new SharedEntryModule(read(), read());
|
|
31
|
+
obj.deserialize(context);
|
|
32
|
+
return obj;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @returns {Set<string>} types available (do not mutate)
|
|
36
|
+
*/
|
|
37
|
+
getSourceTypes() {
|
|
38
|
+
return SOURCE_TYPES;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* @returns {string} a unique identifier of the module
|
|
42
|
+
*/
|
|
43
|
+
identifier() {
|
|
44
|
+
return `shared module ${this._name} ${this._request}`;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* @param {RequestShortener} requestShortener the request shortener
|
|
48
|
+
* @returns {string} a user readable identifier of the module
|
|
49
|
+
*/
|
|
50
|
+
readableIdentifier(requestShortener) {
|
|
51
|
+
return `shared module ${this._name} ${requestShortener.shorten(this._request)}`;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* @param {LibIdentOptions} options options
|
|
55
|
+
* @returns {string | null} an identifier for library inclusion
|
|
56
|
+
*/
|
|
57
|
+
libIdent(options) {
|
|
58
|
+
return `shared module ${this._name}`;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* @param {NeedBuildContext} context context info
|
|
62
|
+
* @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
|
|
63
|
+
* @returns {void}
|
|
64
|
+
*/
|
|
65
|
+
needBuild(context, callback) {
|
|
66
|
+
callback(null, !this.buildMeta);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* @param {WebpackOptions} options webpack options
|
|
70
|
+
* @param {Compilation} compilation the compilation
|
|
71
|
+
* @param {ResolverWithOptions} resolver the resolver
|
|
72
|
+
* @param {InputFileSystem} fs the file system
|
|
73
|
+
* @param {function(WebpackError): void} callback callback function
|
|
74
|
+
* @returns {void}
|
|
75
|
+
*/
|
|
76
|
+
build(options, compilation, resolver, fs, callback) {
|
|
77
|
+
this.buildMeta = {};
|
|
78
|
+
this.buildInfo = {
|
|
79
|
+
strict: true,
|
|
80
|
+
topLevelDeclarations: new Set(['get', 'init']),
|
|
81
|
+
};
|
|
82
|
+
this.buildMeta.exportsType = 'namespace';
|
|
83
|
+
this.clearDependenciesAndBlocks();
|
|
84
|
+
this.addDependency(new StaticExportsDependency(['get', 'init'], false));
|
|
85
|
+
this.addDependency(new SharedDependency_1.default(this._name, this._request));
|
|
86
|
+
callback();
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* @param {CodeGenerationContext} context context for code generation
|
|
90
|
+
* @returns {CodeGenerationResult} result
|
|
91
|
+
*/
|
|
92
|
+
// @ts-ignore
|
|
93
|
+
codeGeneration({
|
|
94
|
+
// @ts-ignore
|
|
95
|
+
chunkGraph,
|
|
96
|
+
// @ts-ignore
|
|
97
|
+
runtimeTemplate, }) {
|
|
98
|
+
const sources = new Map();
|
|
99
|
+
const runtimeRequirements = new Set([
|
|
100
|
+
RuntimeGlobals.definePropertyGetters,
|
|
101
|
+
RuntimeGlobals.hasOwnProperty,
|
|
102
|
+
RuntimeGlobals.exports,
|
|
103
|
+
]);
|
|
104
|
+
const moduleGetter = runtimeTemplate.syncModuleFactory({
|
|
105
|
+
dependency: this.dependencies[1],
|
|
106
|
+
chunkGraph,
|
|
107
|
+
request: this._request,
|
|
108
|
+
runtimeRequirements,
|
|
109
|
+
});
|
|
110
|
+
const source = Template.asString([
|
|
111
|
+
`var moduleGetter = ${moduleGetter};`,
|
|
112
|
+
`var get = ${runtimeTemplate.basicFunction('module, getScope', [
|
|
113
|
+
'return moduleGetter();',
|
|
114
|
+
])};`,
|
|
115
|
+
`var init = ${runtimeTemplate.basicFunction('mfInstance, bundlerRuntime', [
|
|
116
|
+
`${(0, utils_1.getFederationGlobalScope)(RuntimeGlobals)}.instance = mfInstance;`,
|
|
117
|
+
`${(0, utils_1.getFederationGlobalScope)(RuntimeGlobals)}.bundlerRuntime = bundlerRuntime;`,
|
|
118
|
+
`if(!${(0, utils_1.getFederationGlobalScope)(RuntimeGlobals)}.installInitialConsumes) { return Promise.resolve(); }`,
|
|
119
|
+
`return ${(0, utils_1.getFederationGlobalScope)(RuntimeGlobals)}.installInitialConsumes({ asyncLoad: true });`,
|
|
120
|
+
])};`,
|
|
121
|
+
'// This exports getters to disallow modifications',
|
|
122
|
+
`${RuntimeGlobals.definePropertyGetters}(exports, {`,
|
|
123
|
+
Template.indent([
|
|
124
|
+
`get: ${runtimeTemplate.returningFunction('get')},`,
|
|
125
|
+
`init: ${runtimeTemplate.returningFunction('init')}`,
|
|
126
|
+
]),
|
|
127
|
+
'});',
|
|
128
|
+
]);
|
|
129
|
+
sources.set('javascript', this.useSourceMap || this.useSimpleSourceMap
|
|
130
|
+
? new webpackSources.OriginalSource(source, 'webpack/shared-entry')
|
|
131
|
+
: new webpackSources.RawSource(source));
|
|
132
|
+
return {
|
|
133
|
+
sources,
|
|
134
|
+
runtimeRequirements,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* @param {string=} type the source type for which the size should be estimated
|
|
139
|
+
* @returns {number} the estimated size of the module (must be non-zero)
|
|
140
|
+
*/
|
|
141
|
+
size(type) {
|
|
142
|
+
return 42;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* @param {ObjectSerializerContext} context context
|
|
146
|
+
*/
|
|
147
|
+
serialize(context) {
|
|
148
|
+
const { write } = context;
|
|
149
|
+
write(this._name);
|
|
150
|
+
write(this._request);
|
|
151
|
+
super.serialize(context);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
makeSerializable(SharedEntryModule, 'SharedEntryModule');
|
|
155
|
+
exports.default = SharedEntryModule;
|
|
156
|
+
//# sourceMappingURL=SharedEntryModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SharedEntryModule.js","sourceRoot":"","sources":["../../../../../../src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedEntryModule.ts"],"names":[],"mappings":";;;;;AAAA,0FAAqF;AAcrF,0EAAkD;AAClD,4DAA4E;AAE5E,MAAM,gBAAgB,GAAG,OAAO,CAC9B,IAAA,6CAAoB,EAAC,mCAAmC,CAAC,CACJ,CAAC;AACxD,MAAM,EACJ,OAAO,EAAE,cAAc,EACvB,QAAQ,EACR,MAAM,EACN,cAAc,GACf,GAAG,OAAO,CAAC,IAAA,6CAAoB,EAAC,SAAS,CAAC,CAA6B,CAAC;AACzE,MAAM,uBAAuB,GAAG,OAAO,CACrC,IAAA,6CAAoB,EAAC,kDAAkD,CAAC,CACJ,CAAC;AAEvE,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC;AAa7C,MAAM,iBAAkB,SAAQ,MAAM;IAIpC;;;OAGG;IACH,YAAY,IAAY,EAAE,OAAe;QACvC,KAAK,CAAC,qBAAqB,EAAE,IAAI,CAAC,CAAC;QACnC,+CAA+C;QAC/C,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,WAAW,CAAC,OAAkC;QACnD,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;QACzB,MAAM,GAAG,GAAG,IAAI,iBAAiB,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;QAClD,GAAG,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QACzB,OAAO,GAAG,CAAC;IACb,CAAC;IAED;;OAEG;IACM,cAAc;QACrB,OAAO,YAAY,CAAC;IACtB,CAAC;IACD;;OAEG;IACM,UAAU;QACjB,OAAO,iBAAiB,IAAI,CAAC,KAAK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AAO;YACL,OAAO;YACP,mBAAmB;SACpB,CAAC;IACJ,CAAC;IAED;;;OAGG;IACM,IAAI,CAAC,IAAa;QACzB,OAAO,EAAE,CAAC;IACZ,CAAC;IACD;;OAEG;IACM,SAAS,CAAC,OAAgC;QACjD,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;QAC1B,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAClB,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACrB,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;CACF;AAED,gBAAgB,CAAC,iBAAiB,EAAE,mBAAmB,CAAC,CAAC;AAEzD,kBAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare const ModuleFactory: typeof import("webpack/lib/ModuleFactory");
|
|
2
|
+
import type { ModuleFactoryCreateData, ModuleFactoryResult } from 'webpack/lib/ModuleFactory';
|
|
3
|
+
export default class SharedEntryModuleFactory extends ModuleFactory {
|
|
4
|
+
/**
|
|
5
|
+
* @param {ModuleFactoryCreateData} data data object
|
|
6
|
+
* @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
|
|
7
|
+
* @returns {void}
|
|
8
|
+
*/
|
|
9
|
+
create(data: ModuleFactoryCreateData, callback: (error: Error | null, result: ModuleFactoryResult) => void): void;
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const normalize_webpack_path_1 = require("@module-federation/sdk/normalize-webpack-path");
|
|
7
|
+
const SharedEntryModule_1 = __importDefault(require("./SharedEntryModule"));
|
|
8
|
+
const ModuleFactory = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack/lib/ModuleFactory'));
|
|
9
|
+
class SharedEntryModuleFactory extends ModuleFactory {
|
|
10
|
+
/**
|
|
11
|
+
* @param {ModuleFactoryCreateData} data data object
|
|
12
|
+
* @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
|
|
13
|
+
* @returns {void}
|
|
14
|
+
*/
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
create(data, callback) {
|
|
17
|
+
const { dependencies } = data;
|
|
18
|
+
const containerDependencies = dependencies;
|
|
19
|
+
const dep = containerDependencies[0];
|
|
20
|
+
callback(null, {
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
module: new SharedEntryModule_1.default(dep.name, dep.request),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.default = SharedEntryModuleFactory;
|
|
27
|
+
//# sourceMappingURL=SharedEntryModuleFactory.js.map
|
package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedEntryModuleFactory.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SharedEntryModuleFactory.js","sourceRoot":"","sources":["../../../../../../src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedEntryModuleFactory.ts"],"names":[],"mappings":";;;;;AAAA,0FAAqF;AAErF,4EAAoD;AAEpD,MAAM,aAAa,GAAG,OAAO,CAC3B,IAAA,6CAAoB,EAAC,2BAA2B,CAAC,CACJ,CAAC;AAMhD,MAAqB,wBAAyB,SAAQ,aAAa;IACjE;;;;OAIG;IACH,aAAa;IACJ,MAAM,CACb,IAA6B,EAC7B,QAAoE;QAEpE,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC;QAC9B,MAAM,qBAAqB,GACzB,YAAkD,CAAC;QACrD,MAAM,GAAG,GAAG,qBAAqB,CAAC,CAAC,CAAC,CAAC;QAErC,QAAQ,CAAC,IAAI,EAAE;YACb,aAAa;YACb,MAAM,EAAE,IAAI,2BAAiB,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC;SACrD,CAAC,CAAC;IACL,CAAC;CACF;AArBD,2CAqBC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { WebpackPluginInstance, Compiler } from 'webpack';
|
|
2
|
+
import { moduleFederationPlugin } from '@module-federation/sdk';
|
|
3
|
+
import { ReferencedExports } from './SharedUsedExportsOptimizerRuntimeModule';
|
|
4
|
+
import { NormalizedSharedOptions } from '../SharePlugin';
|
|
5
|
+
export type CustomReferencedExports = {
|
|
6
|
+
[sharedName: string]: string[];
|
|
7
|
+
};
|
|
8
|
+
export default class SharedUsedExportsOptimizerPlugin implements WebpackPluginInstance {
|
|
9
|
+
name: string;
|
|
10
|
+
sharedReferencedExports: ReferencedExports;
|
|
11
|
+
private sharedOptions;
|
|
12
|
+
private injectTreeShakingUsedExports;
|
|
13
|
+
private manifestOptions;
|
|
14
|
+
ignoredRuntime: string[];
|
|
15
|
+
constructor(sharedOptions: NormalizedSharedOptions, injectTreeShakingUsedExports?: boolean, ignoredRuntime?: string[], manifestOptions?: moduleFederationPlugin.ModuleFederationPluginOptions['manifest']);
|
|
16
|
+
private applyCustomReferencedExports;
|
|
17
|
+
apply(compiler: Compiler): void;
|
|
18
|
+
}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const sdk_1 = require("@module-federation/sdk");
|
|
7
|
+
const SharedUsedExportsOptimizerRuntimeModule_1 = __importDefault(require("./SharedUsedExportsOptimizerRuntimeModule"));
|
|
8
|
+
function isHarmonyImportSpecifierDependency(dependency) {
|
|
9
|
+
return dependency.type === 'harmony import specifier';
|
|
10
|
+
}
|
|
11
|
+
// dynamic import import('ui-lib')
|
|
12
|
+
function isImportDependency(dependency) {
|
|
13
|
+
return dependency.type === 'import()';
|
|
14
|
+
}
|
|
15
|
+
class SharedUsedExportsOptimizerPlugin {
|
|
16
|
+
constructor(sharedOptions, injectTreeShakingUsedExports, ignoredRuntime, manifestOptions) {
|
|
17
|
+
this.name = 'SharedUsedExportsOptimizerPlugin';
|
|
18
|
+
this.sharedOptions = sharedOptions;
|
|
19
|
+
this.injectTreeShakingUsedExports = injectTreeShakingUsedExports ?? true;
|
|
20
|
+
this.manifestOptions = manifestOptions ?? {};
|
|
21
|
+
this.sharedReferencedExports = new Map();
|
|
22
|
+
this.sharedOptions.forEach(([key, config]) => {
|
|
23
|
+
if (!config.treeShaking) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
this.sharedReferencedExports.set(key, new Set());
|
|
27
|
+
});
|
|
28
|
+
this.ignoredRuntime = ignoredRuntime || [];
|
|
29
|
+
}
|
|
30
|
+
applyCustomReferencedExports() {
|
|
31
|
+
const { sharedReferencedExports, sharedOptions } = this;
|
|
32
|
+
const addCustomExports = (shareKey, exports) => {
|
|
33
|
+
if (!sharedReferencedExports.get(shareKey)) {
|
|
34
|
+
sharedReferencedExports.set(shareKey, new Set());
|
|
35
|
+
}
|
|
36
|
+
const sharedExports = sharedReferencedExports.get(shareKey);
|
|
37
|
+
exports.forEach((item) => {
|
|
38
|
+
sharedExports.add(item);
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
sharedOptions.forEach(([shareKey, config]) => {
|
|
42
|
+
if (config.treeShaking?.usedExports) {
|
|
43
|
+
addCustomExports(shareKey, config.treeShaking.usedExports);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
apply(compiler) {
|
|
48
|
+
const { sharedReferencedExports, sharedOptions, injectTreeShakingUsedExports, manifestOptions, } = this;
|
|
49
|
+
if (!sharedOptions.length) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
compiler.hooks.compilation.tap('SharedUsedExportsOptimizerPlugin', (compilation) => {
|
|
53
|
+
// collect referenced export
|
|
54
|
+
compilation.hooks.dependencyReferencedExports.tap('SharedUsedExportsOptimizerPlugin', (referencedExports, dependency, runtime) => {
|
|
55
|
+
if (!('request' in dependency)) {
|
|
56
|
+
return referencedExports;
|
|
57
|
+
}
|
|
58
|
+
const shareKey = dependency.request;
|
|
59
|
+
if (typeof shareKey !== 'string' ||
|
|
60
|
+
sharedOptions.every(([key]) => key !== shareKey)) {
|
|
61
|
+
return referencedExports;
|
|
62
|
+
}
|
|
63
|
+
let currentReferencedExports = referencedExports;
|
|
64
|
+
if (isImportDependency(dependency) &&
|
|
65
|
+
referencedExports ===
|
|
66
|
+
compilation.compiler.webpack.Dependency
|
|
67
|
+
.EXPORTS_OBJECT_REFERENCED) {
|
|
68
|
+
sharedReferencedExports.delete(shareKey);
|
|
69
|
+
return currentReferencedExports;
|
|
70
|
+
}
|
|
71
|
+
if (isHarmonyImportSpecifierDependency(dependency) &&
|
|
72
|
+
dependency.ids &&
|
|
73
|
+
dependency.ids[0] === 'default') {
|
|
74
|
+
const { ids, referencedPropertiesInDestructuring } = dependency;
|
|
75
|
+
const getOriginalReferencedExports = () => {
|
|
76
|
+
if (referencedPropertiesInDestructuring) {
|
|
77
|
+
/** @type {string[][]} */
|
|
78
|
+
const refs = [];
|
|
79
|
+
for (const key of referencedPropertiesInDestructuring) {
|
|
80
|
+
refs.push({
|
|
81
|
+
name: ids ? ids.concat([key]) : [key],
|
|
82
|
+
canMangle: false,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return refs;
|
|
86
|
+
}
|
|
87
|
+
return ids ? [ids] : [[]];
|
|
88
|
+
};
|
|
89
|
+
currentReferencedExports = getOriginalReferencedExports();
|
|
90
|
+
}
|
|
91
|
+
if (!currentReferencedExports.length) {
|
|
92
|
+
return referencedExports;
|
|
93
|
+
}
|
|
94
|
+
currentReferencedExports.forEach((item) => {
|
|
95
|
+
if (typeof runtime !== 'string') {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const exportNames = [];
|
|
99
|
+
if (Array.isArray(item)) {
|
|
100
|
+
exportNames.push(...item);
|
|
101
|
+
}
|
|
102
|
+
else if (Array.isArray(item.name)) {
|
|
103
|
+
exportNames.push(...item.name);
|
|
104
|
+
}
|
|
105
|
+
exportNames.forEach((i) => {
|
|
106
|
+
const moduleExports = sharedReferencedExports.get(shareKey);
|
|
107
|
+
if (!moduleExports) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
moduleExports.add(i);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
return referencedExports;
|
|
114
|
+
});
|
|
115
|
+
// treeShaking shared module
|
|
116
|
+
compilation.hooks.optimizeDependencies.tap({
|
|
117
|
+
name: 'SharedUsedExportsOptimizerPlugin',
|
|
118
|
+
stage: 1,
|
|
119
|
+
}, (modules) => {
|
|
120
|
+
this.applyCustomReferencedExports();
|
|
121
|
+
const sharedModules = [...modules].filter((m) => [
|
|
122
|
+
'consume-shared-module',
|
|
123
|
+
'provide-module',
|
|
124
|
+
'shared-entry-module',
|
|
125
|
+
].includes(m.type));
|
|
126
|
+
const moduleGraph = compilation.moduleGraph;
|
|
127
|
+
sharedModules.forEach((module) => {
|
|
128
|
+
const shareKey = module.options?.shareKey ||
|
|
129
|
+
// @ts-expect-error FIXME: need to add general shareKey field
|
|
130
|
+
module._name ||
|
|
131
|
+
// @ts-ignore
|
|
132
|
+
module._name;
|
|
133
|
+
if (!shareKey) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (!sharedOptions.find(([key]) => key === shareKey)?.[1]
|
|
137
|
+
.treeShaking) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const referenceExports = sharedReferencedExports.get(shareKey);
|
|
141
|
+
if (!referenceExports || !referenceExports.size) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const realSharedModule = [...modules].find((m) => 'rawRequest' in m && m.rawRequest === shareKey);
|
|
145
|
+
if (realSharedModule?.factoryMeta?.sideEffectFree !== true) {
|
|
146
|
+
referenceExports.clear();
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
// mark used exports
|
|
150
|
+
const handleDependency = (dep) => {
|
|
151
|
+
const usedExport = [...referenceExports];
|
|
152
|
+
const referencedModule = moduleGraph.getModule(dep);
|
|
153
|
+
if (!referencedModule)
|
|
154
|
+
return;
|
|
155
|
+
const exportsInfo = moduleGraph.getExportsInfo(referencedModule);
|
|
156
|
+
for (let i = 0; i < usedExport.length; i++) {
|
|
157
|
+
const exportInfo = exportsInfo.getExportInfo(usedExport[i]);
|
|
158
|
+
exportInfo.setUsed(compiler.webpack.UsageState.Used, undefined);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
module.blocks.forEach((block) => {
|
|
162
|
+
block.dependencies.forEach((dep) => {
|
|
163
|
+
handleDependency(dep);
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
module.dependencies.forEach((dep) => {
|
|
167
|
+
handleDependency(dep);
|
|
168
|
+
});
|
|
169
|
+
module.factoryMeta ||= {};
|
|
170
|
+
module.factoryMeta.sideEffectFree = true;
|
|
171
|
+
if (!realSharedModule) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const exportsInfo = compilation.moduleGraph.getExportsInfo(realSharedModule);
|
|
175
|
+
let canUpdateModuleUsedStage = true;
|
|
176
|
+
for (const subExport of exportsInfo.exports) {
|
|
177
|
+
const used = subExport.getUsed(undefined);
|
|
178
|
+
if (used !== 3 && used !== 0) {
|
|
179
|
+
if (referenceExports.has(subExport.name)) {
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
canUpdateModuleUsedStage = false;
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (canUpdateModuleUsedStage) {
|
|
187
|
+
for (const exportInfo of exportsInfo.exports) {
|
|
188
|
+
exportInfo.setUsedConditionally((used) => used === 3, 0, undefined);
|
|
189
|
+
}
|
|
190
|
+
// exportsInfo.otherExportsInfo.setUsedConditionally(
|
|
191
|
+
// (used) => used === 3,
|
|
192
|
+
// 0,
|
|
193
|
+
// undefined,
|
|
194
|
+
// );
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
// inject reference exports to stats
|
|
199
|
+
if (manifestOptions) {
|
|
200
|
+
compilation.hooks.processAssets.tapPromise({
|
|
201
|
+
name: 'injectReferenceExports',
|
|
202
|
+
stage: compilation.constructor
|
|
203
|
+
.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER,
|
|
204
|
+
}, async () => {
|
|
205
|
+
const { statsFileName } = (0, sdk_1.getManifestFileName)(manifestOptions);
|
|
206
|
+
const stats = compilation.getAsset(statsFileName);
|
|
207
|
+
if (!stats) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const statsContent = JSON.parse(stats.source.source().toString());
|
|
211
|
+
for (const key of sharedReferencedExports.keys()) {
|
|
212
|
+
const sharedModule = statsContent.shared.find((s) => s.name === key);
|
|
213
|
+
if (!sharedModule) {
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
const sharedReferenceExports = sharedReferencedExports.get(key);
|
|
217
|
+
if (!sharedReferenceExports) {
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
sharedModule.usedExports = [...sharedReferenceExports];
|
|
221
|
+
}
|
|
222
|
+
compilation.updateAsset(statsFileName, new compiler.webpack.sources.RawSource(JSON.stringify(statsContent, null, 2)));
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
if (!injectTreeShakingUsedExports) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
compilation.hooks.additionalTreeRuntimeRequirements.tap('SharedUsedExportsOptimizerPlugin', (chunk, set) => {
|
|
229
|
+
set.add(compiler.webpack.RuntimeGlobals.runtimeId);
|
|
230
|
+
// inject usedExports info to bundler runtime
|
|
231
|
+
compilation.addRuntimeModule(chunk, new SharedUsedExportsOptimizerRuntimeModule_1.default(this.sharedReferencedExports));
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
exports.default = SharedUsedExportsOptimizerPlugin;
|
|
237
|
+
//# sourceMappingURL=SharedUsedExportsOptimizerPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SharedUsedExportsOptimizerPlugin.js","sourceRoot":"","sources":["../../../../../src/lib/sharing/tree-shaking/SharedUsedExportsOptimizerPlugin.ts"],"names":[],"mappings":";;;;;AAMA,gDAIgC;AAChC,wHAEmD;AAQnD,SAAS,kCAAkC,CACzC,UAAsB;IAEtB,OAAO,UAAU,CAAC,IAAI,KAAK,0BAA0B,CAAC;AACxD,CAAC;AAED,kCAAkC;AAClC,SAAS,kBAAkB,CAAC,UAAsB;IAChD,OAAO,UAAU,CAAC,IAAI,KAAK,UAAU,CAAC;AACxC,CAAC;AAED,MAAqB,gCAAgC;IAWnD,YACE,aAAsC,EACtC,4BAAsC,EACtC,cAAyB,EACzB,eAAkF;QAZpF,SAAI,GAAG,kCAAkC,CAAC;QAcxC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,4BAA4B,GAAG,4BAA4B,IAAI,IAAI,CAAC;QACzE,IAAI,CAAC,eAAe,GAAG,eAAe,IAAI,EAAE,CAAC;QAC7C,IAAI,CAAC,uBAAuB,GAAG,IAAI,GAAG,EAAE,CAAC;QACzC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,EAAE;YAC3C,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;gBACxB,OAAO;YACT,CAAC;YACD,IAAI,CAAC,uBAAuB,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;QACnD,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,cAAc,GAAG,cAAc,IAAI,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runtime id to Set of exported names
|
|
3
|
+
* @example {
|
|
4
|
+
* 'antd': Set(['Button', 'exportedName2']),
|
|
5
|
+
* }
|
|
6
|
+
*/
|
|
7
|
+
export type ReferencedExports = Map<string, Set<string>>;
|
|
8
|
+
declare const RuntimeModule: typeof import("webpack").RuntimeModule;
|
|
9
|
+
declare class SharedUsedExportsOptimizerRuntimeModule extends RuntimeModule {
|
|
10
|
+
private sharedUsedExports;
|
|
11
|
+
constructor(sharedUsedExports: ReferencedExports);
|
|
12
|
+
/**
|
|
13
|
+
* @returns {string | null} runtime code
|
|
14
|
+
*/
|
|
15
|
+
generate(): string | null;
|
|
16
|
+
}
|
|
17
|
+
export default SharedUsedExportsOptimizerRuntimeModule;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const normalize_webpack_path_1 = require("@module-federation/sdk/normalize-webpack-path");
|
|
4
|
+
const utils_1 = require("../../container/runtime/utils");
|
|
5
|
+
const { Template, RuntimeGlobals, RuntimeModule } = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack'));
|
|
6
|
+
class SharedUsedExportsOptimizerRuntimeModule extends RuntimeModule {
|
|
7
|
+
constructor(sharedUsedExports) {
|
|
8
|
+
super('shared-used-exports', RuntimeModule.STAGE_ATTACH);
|
|
9
|
+
this.sharedUsedExports = sharedUsedExports;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* @returns {string | null} runtime code
|
|
13
|
+
*/
|
|
14
|
+
generate() {
|
|
15
|
+
if (!this.sharedUsedExports) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
const federationGlobal = (0, utils_1.getFederationGlobalScope)(RuntimeGlobals);
|
|
19
|
+
return Template.asString([
|
|
20
|
+
`if(!${federationGlobal}) {return;}`,
|
|
21
|
+
`${federationGlobal}.usedExports = ${JSON.stringify(Array.from(this.sharedUsedExports.entries()).reduce((acc, [pkg, moduleMap]) => {
|
|
22
|
+
acc[pkg] = Array.from(moduleMap);
|
|
23
|
+
return acc;
|
|
24
|
+
}, {}))};`,
|
|
25
|
+
]);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.default = SharedUsedExportsOptimizerRuntimeModule;
|
|
29
|
+
//# sourceMappingURL=SharedUsedExportsOptimizerRuntimeModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SharedUsedExportsOptimizerRuntimeModule.js","sourceRoot":"","sources":["../../../../../src/lib/sharing/tree-shaking/SharedUsedExportsOptimizerRuntimeModule.ts"],"names":[],"mappings":";;AAAA,0FAAqF;AAErF,yDAAyE;AAUzE,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,aAAa,EAAE,GAAG,OAAO,CACzD,IAAA,6CAAoB,EAAC,SAAS,CAAC,CACJ,CAAC;AAE9B,MAAM,uCAAwC,SAAQ,aAAa;IAGjE,YAAY,iBAAoC;QAC9C,KAAK,CAAC,qBAAqB,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;QACzD,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;IAC7C,CAAC;IAED;;OAEG;IACM,QAAQ;QACf,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC;YAC5B,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,gBAAgB,GAAG,IAAA,gCAAwB,EAAC,cAAc,CAAC,CAAC;QAClE,OAAO,QAAQ,CAAC,QAAQ,CAAC;YACvB,OAAO,gBAAgB,aAAa;YACpC,GAAG,gBAAgB,kBAAkB,IAAI,CAAC,SAAS,CACjD,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,CAAC,CAAC,MAAM,CACjD,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,SAAS,CAAC,EAAE,EAAE;gBACxB,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;gBACjC,OAAO,GAAG,CAAC;YACb,CAAC,EACD,EAA8B,CAC/B,CACF,GAAG;SACL,CAAC,CAAC;IACL,CAAC;CACF;AAED,kBAAe,uCAAuC,CAAC"}
|