@module-federation/node 0.0.0-feat-node-support-1702694175665
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/jest.config.d.ts +11 -0
- package/jest.config.js +19 -0
- package/jest.config.js.map +1 -0
- package/package.json +66 -0
- package/src/filesystem/stratagies.d.ts +18 -0
- package/src/filesystem/stratagies.js +124 -0
- package/src/filesystem/stratagies.js.map +1 -0
- package/src/index.d.ts +5 -0
- package/src/index.js +17 -0
- package/src/index.js.map +1 -0
- package/src/plugins/AutomaticPublicPathPlugin.d.ts +9 -0
- package/src/plugins/AutomaticPublicPathPlugin.js +38 -0
- package/src/plugins/AutomaticPublicPathPlugin.js.map +1 -0
- package/src/plugins/ChunkCorrelationPlugin.d.ts +61 -0
- package/src/plugins/ChunkCorrelationPlugin.js +442 -0
- package/src/plugins/ChunkCorrelationPlugin.js.map +1 -0
- package/src/plugins/CommonJsChunkLoadingPlugin.d.ts +17 -0
- package/src/plugins/CommonJsChunkLoadingPlugin.js +121 -0
- package/src/plugins/CommonJsChunkLoadingPlugin.js.map +1 -0
- package/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.d.ts +39 -0
- package/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.js +119 -0
- package/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.js.map +1 -0
- package/src/plugins/NodeFederationPlugin.d.ts +46 -0
- package/src/plugins/NodeFederationPlugin.js +76 -0
- package/src/plugins/NodeFederationPlugin.js.map +1 -0
- package/src/plugins/RemotePublicPathRuntimeModule.d.ts +10 -0
- package/src/plugins/RemotePublicPathRuntimeModule.js +109 -0
- package/src/plugins/RemotePublicPathRuntimeModule.js.map +1 -0
- package/src/plugins/StreamingTargetPlugin.d.ts +28 -0
- package/src/plugins/StreamingTargetPlugin.js +59 -0
- package/src/plugins/StreamingTargetPlugin.js.map +1 -0
- package/src/plugins/UniversalFederationPlugin.d.ts +43 -0
- package/src/plugins/UniversalFederationPlugin.js +53 -0
- package/src/plugins/UniversalFederationPlugin.js.map +1 -0
- package/src/plugins/webpackChunkUtilities.d.ts +50 -0
- package/src/plugins/webpackChunkUtilities.js +321 -0
- package/src/plugins/webpackChunkUtilities.js.map +1 -0
- package/src/types/index.d.ts +3 -0
- package/src/types/index.js +3 -0
- package/src/types/index.js.map +1 -0
- package/src/utils/flush-chunks.d.ts +10 -0
- package/src/utils/flush-chunks.js +162 -0
- package/src/utils/flush-chunks.js.map +1 -0
- package/src/utils/hot-reload.d.ts +7 -0
- package/src/utils/hot-reload.js +142 -0
- package/src/utils/hot-reload.js.map +1 -0
- package/src/utils/index.d.ts +2 -0
- package/src/utils/index.js +19 -0
- package/src/utils/index.js.map +1 -0
|
@@ -0,0 +1,119 @@
|
|
|
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 { RuntimeGlobals, RuntimeModule } = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack'));
|
|
5
|
+
const { getUndoPath } = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack/lib/util/identifier'));
|
|
6
|
+
const tapable_1 = require("tapable");
|
|
7
|
+
const compileBooleanMatcher = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack/lib/util/compileBooleanMatcher'));
|
|
8
|
+
const webpackChunkUtilities_1 = require("./webpackChunkUtilities");
|
|
9
|
+
const stratagies_1 = require("../filesystem/stratagies");
|
|
10
|
+
class DynamicFilesystemChunkLoadingRuntimeModule extends RuntimeModule {
|
|
11
|
+
constructor(runtimeRequirements, options, chunkLoadingContext) {
|
|
12
|
+
super('readFile chunk loading', RuntimeModule.STAGE_ATTACH + 1);
|
|
13
|
+
this.hooks = {
|
|
14
|
+
strategyCase: new tapable_1.SyncWaterfallHook(['source']),
|
|
15
|
+
};
|
|
16
|
+
this.runtimeRequirements = runtimeRequirements;
|
|
17
|
+
this.options = options;
|
|
18
|
+
this.chunkLoadingContext = chunkLoadingContext;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @private
|
|
22
|
+
* @param {Chunk} chunk chunk
|
|
23
|
+
* @param {string} rootOutputDir root output directory
|
|
24
|
+
* @returns {string} generated code
|
|
25
|
+
*/
|
|
26
|
+
_generateBaseUri(chunk, rootOutputDir) {
|
|
27
|
+
const options = chunk.getEntryOptions();
|
|
28
|
+
if (options && options.baseUri) {
|
|
29
|
+
return `${RuntimeGlobals.baseURI} = ${JSON.stringify(options.baseUri)};`;
|
|
30
|
+
}
|
|
31
|
+
return `${RuntimeGlobals.baseURI} = require("url").pathToFileURL(${rootOutputDir
|
|
32
|
+
? `__dirname + ${JSON.stringify('/' + rootOutputDir)}`
|
|
33
|
+
: '__filename'});`;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* @private
|
|
37
|
+
* @param {unknown[]} items item to log
|
|
38
|
+
*/
|
|
39
|
+
_getLogger(...items) {
|
|
40
|
+
if (!this.options.debug) {
|
|
41
|
+
return '';
|
|
42
|
+
}
|
|
43
|
+
return `console.log(${items.join(',')});`;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @returns {string} runtime code
|
|
47
|
+
*/
|
|
48
|
+
generate() {
|
|
49
|
+
const { remotes = {}, name } = this.options;
|
|
50
|
+
const { webpack } = this.chunkLoadingContext;
|
|
51
|
+
const { chunkGraph, chunk, compilation } = this;
|
|
52
|
+
const { Template } = webpack;
|
|
53
|
+
if (!chunkGraph || !chunk || !compilation) {
|
|
54
|
+
console.warn('Missing required properties. Returning empty string.');
|
|
55
|
+
return '';
|
|
56
|
+
}
|
|
57
|
+
const { runtimeTemplate } = compilation;
|
|
58
|
+
const jsModulePlugin = webpack?.javascript?.JavascriptModulesPlugin ||
|
|
59
|
+
require('webpack/lib/javascript/JavascriptModulesPlugin');
|
|
60
|
+
const { chunkHasJs } = jsModulePlugin;
|
|
61
|
+
const fn = RuntimeGlobals.ensureChunkHandlers;
|
|
62
|
+
const conditionMap = chunkGraph.getChunkConditionMap(chunk, chunkHasJs);
|
|
63
|
+
const hasJsMatcher = compileBooleanMatcher(conditionMap);
|
|
64
|
+
const initialChunkIds = (0, webpackChunkUtilities_1.getInitialChunkIds)(chunk, chunkGraph, chunkHasJs);
|
|
65
|
+
const outputName = compilation.getPath(jsModulePlugin.getChunkFilenameTemplate(chunk, compilation.outputOptions), { chunk, contentHashType: 'javascript' });
|
|
66
|
+
const rootOutputDir = getUndoPath(outputName, compilation.outputOptions.path, false);
|
|
67
|
+
const stateExpression = this.runtimeRequirements.has(RuntimeGlobals.hmrDownloadUpdateHandlers)
|
|
68
|
+
? `${RuntimeGlobals.hmrRuntimeStatePrefix}_readFileVm`
|
|
69
|
+
: undefined;
|
|
70
|
+
const dynamicFilesystemChunkLoadingPluginCode = Template.asString([
|
|
71
|
+
stratagies_1.fileSystemRunInContextStrategy.toString(),
|
|
72
|
+
stratagies_1.httpEvalStrategy.toString(),
|
|
73
|
+
stratagies_1.httpVmStrategy.toString(),
|
|
74
|
+
'const loadChunkStrategy = async (strategyType,chunkId,rootOutputDir, remotes, callback) => {',
|
|
75
|
+
Template.indent([
|
|
76
|
+
'switch (strategyType) {',
|
|
77
|
+
Template.indent([
|
|
78
|
+
'case "filesystem": return await fileSystemRunInContextStrategy(chunkId,rootOutputDir, remotes, callback);',
|
|
79
|
+
'case "http-eval": return await httpEvalStrategy(chunkId,rootOutputDir, remotes, callback);',
|
|
80
|
+
'case "http-vm": return await httpVmStrategy(chunkId,rootOutputDir, remotes, callback);',
|
|
81
|
+
this.hooks.strategyCase.call('default: throw new Error("Invalid strategy type");'),
|
|
82
|
+
]),
|
|
83
|
+
'}',
|
|
84
|
+
]),
|
|
85
|
+
'};',
|
|
86
|
+
]);
|
|
87
|
+
return Template.asString([
|
|
88
|
+
dynamicFilesystemChunkLoadingPluginCode,
|
|
89
|
+
this.runtimeRequirements.has(RuntimeGlobals.baseURI)
|
|
90
|
+
? this._generateBaseUri(chunk, rootOutputDir)
|
|
91
|
+
: '// no baseURI',
|
|
92
|
+
'',
|
|
93
|
+
'// object to store loaded chunks',
|
|
94
|
+
'// "0" means "already loaded", Promise means loading',
|
|
95
|
+
`var installedChunks = ${stateExpression ? `${stateExpression} = ${stateExpression} || ` : ''}{`,
|
|
96
|
+
Template.indent(Array.from(initialChunkIds, (id) => `${JSON.stringify(id)}: 0`).join(',\n')),
|
|
97
|
+
'};',
|
|
98
|
+
'',
|
|
99
|
+
(0, webpackChunkUtilities_1.handleOnChunkLoad)(this.runtimeRequirements.has(RuntimeGlobals.onChunksLoaded), runtimeTemplate),
|
|
100
|
+
'',
|
|
101
|
+
(0, webpackChunkUtilities_1.generateInstallChunk)(runtimeTemplate, this.runtimeRequirements.has(RuntimeGlobals.onChunksLoaded)),
|
|
102
|
+
'',
|
|
103
|
+
this.runtimeRequirements.has(RuntimeGlobals.ensureChunkHandlers)
|
|
104
|
+
? (0, webpackChunkUtilities_1.generateLoadScript)(runtimeTemplate)
|
|
105
|
+
: '// no remote script loader needed',
|
|
106
|
+
this.runtimeRequirements.has(RuntimeGlobals.ensureChunkHandlers)
|
|
107
|
+
? (0, webpackChunkUtilities_1.generateLoadingCode)(this.runtimeRequirements.has(RuntimeGlobals.ensureChunkHandlers), fn, hasJsMatcher, rootOutputDir, remotes, name)
|
|
108
|
+
: '// no chunk loading',
|
|
109
|
+
'',
|
|
110
|
+
(0, webpackChunkUtilities_1.generateExternalInstallChunkCode)(this.runtimeRequirements.has(RuntimeGlobals.externalInstallChunk), this.options.debug),
|
|
111
|
+
'',
|
|
112
|
+
(0, webpackChunkUtilities_1.generateHmrCode)(this.runtimeRequirements.has(RuntimeGlobals.hmrDownloadUpdateHandlers), rootOutputDir),
|
|
113
|
+
'',
|
|
114
|
+
(0, webpackChunkUtilities_1.generateHmrManifestCode)(this.runtimeRequirements.has(RuntimeGlobals.hmrDownloadManifest), rootOutputDir),
|
|
115
|
+
]);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
exports.default = DynamicFilesystemChunkLoadingRuntimeModule;
|
|
119
|
+
//# sourceMappingURL=DynamicFilesystemChunkLoadingRuntimeModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DynamicFilesystemChunkLoadingRuntimeModule.js","sourceRoot":"","sources":["../../../../../packages/node/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.ts"],"names":[],"mappings":";;AAIA,0FAAqF;AACrF,MAAM,EAAE,cAAc,EAAE,aAAa,EAAE,GAAG,OAAO,CAC/C,IAAA,6CAAoB,EAAC,SAAS,CAAC,CACJ,CAAC;AAC9B,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAC7B,IAAA,6CAAoB,EAAC,6BAA6B,CAAC,CACJ,CAAC;AAClD,qCAA4C;AAC5C,MAAM,qBAAqB,GAAG,OAAO,CACnC,IAAA,6CAAoB,EAAC,wCAAwC,CAAC,CACJ,CAAC;AAC7D,mEASiC;AACjC,yDAIkC;AAmBlC,MAAM,0CAA2C,SAAQ,aAAa;IAQpE,YACE,mBAAgC,EAChC,OAA0D,EAC1D,mBAAwC;QAExC,KAAK,CAAC,wBAAwB,EAAE,aAAa,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC;QATlE,UAAK,GAAG;YACN,YAAY,EAAE,IAAI,2BAAiB,CAAC,CAAC,QAAQ,CAAC,CAAC;SAChD,CAAC;QAQA,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAC;QAE/C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAC;IACjD,CAAC;IAED;;;;;OAKG;IACH,gBAAgB,CAAC,KAAY,EAAE,aAAqB;QAClD,MAAM,OAAO,GAAG,KAAK,CAAC,eAAe,EAAE,CAAC;QACxC,IAAI,OAAO,IAAI,OAAO,CAAC,OAAO,EAAE;YAC9B,OAAO,GAAG,cAAc,CAAC,O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aAAa,CACd;YACD,EAAE;YACF,IAAA,+CAAuB,EACrB,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,cAAc,CAAC,mBAAmB,CAAC,EAChE,aAAa,CACd;SACF,CAAC,CAAC;IACL,CAAC;CACF;AAED,kBAAe,0CAA0C,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Compiler, container } from 'webpack';
|
|
2
|
+
import type { ModuleFederationPluginOptions } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Interface for NodeFederationOptions which extends ModuleFederationPluginOptions
|
|
5
|
+
* @interface
|
|
6
|
+
* @property {Record<string, unknown>} experiments - Optional experiments configuration
|
|
7
|
+
* @property {boolean} debug - Optional debug flag
|
|
8
|
+
*/
|
|
9
|
+
interface NodeFederationOptions extends ModuleFederationPluginOptions {
|
|
10
|
+
experiments?: Record<string, unknown>;
|
|
11
|
+
debug?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Interface for Context
|
|
15
|
+
* @interface
|
|
16
|
+
* @property {typeof container.ModuleFederationPlugin} ModuleFederationPlugin - Optional ModuleFederationPlugin
|
|
17
|
+
*/
|
|
18
|
+
interface Context {
|
|
19
|
+
ModuleFederationPlugin?: typeof container.ModuleFederationPlugin;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Class representing a NodeFederationPlugin.
|
|
23
|
+
* @class
|
|
24
|
+
*/
|
|
25
|
+
declare class NodeFederationPlugin {
|
|
26
|
+
private _options;
|
|
27
|
+
private context;
|
|
28
|
+
private experiments;
|
|
29
|
+
/**
|
|
30
|
+
* Create a NodeFederationPlugin.
|
|
31
|
+
* @constructor
|
|
32
|
+
* @param {NodeFederationOptions} options - The options for the NodeFederationPlugin
|
|
33
|
+
* @param {Context} context - The context for the NodeFederationPlugin
|
|
34
|
+
*/
|
|
35
|
+
constructor({ experiments, debug, ...options }: NodeFederationOptions, context: Context);
|
|
36
|
+
/**
|
|
37
|
+
* Apply method for the NodeFederationPlugin class.
|
|
38
|
+
* @method
|
|
39
|
+
* @param {Compiler} compiler - The webpack compiler.
|
|
40
|
+
*/
|
|
41
|
+
apply(compiler: Compiler): void;
|
|
42
|
+
private preparePluginOptions;
|
|
43
|
+
private updateCompilerOptions;
|
|
44
|
+
private getModuleFederationPlugin;
|
|
45
|
+
}
|
|
46
|
+
export default NodeFederationPlugin;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const enhanced_1 = require("@module-federation/enhanced");
|
|
4
|
+
/**
|
|
5
|
+
* Class representing a NodeFederationPlugin.
|
|
6
|
+
* @class
|
|
7
|
+
*/
|
|
8
|
+
class NodeFederationPlugin {
|
|
9
|
+
/**
|
|
10
|
+
* Create a NodeFederationPlugin.
|
|
11
|
+
* @constructor
|
|
12
|
+
* @param {NodeFederationOptions} options - The options for the NodeFederationPlugin
|
|
13
|
+
* @param {Context} context - The context for the NodeFederationPlugin
|
|
14
|
+
*/
|
|
15
|
+
constructor({ experiments, debug, ...options }, context) {
|
|
16
|
+
this._options = options || {};
|
|
17
|
+
this.context = context || {};
|
|
18
|
+
this.experiments = experiments || {};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Apply method for the NodeFederationPlugin class.
|
|
22
|
+
* @method
|
|
23
|
+
* @param {Compiler} compiler - The webpack compiler.
|
|
24
|
+
*/
|
|
25
|
+
apply(compiler) {
|
|
26
|
+
const { webpack } = compiler;
|
|
27
|
+
new enhanced_1.ModuleInfoRuntimePlugin().apply(compiler);
|
|
28
|
+
const pluginOptions = this.preparePluginOptions();
|
|
29
|
+
this.updateCompilerOptions(compiler);
|
|
30
|
+
const ModuleFederationPlugin = this.getModuleFederationPlugin(compiler, webpack);
|
|
31
|
+
new ModuleFederationPlugin(pluginOptions).apply(compiler);
|
|
32
|
+
}
|
|
33
|
+
preparePluginOptions() {
|
|
34
|
+
return {
|
|
35
|
+
...this._options,
|
|
36
|
+
remotes: this._options.remotes || {},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
updateCompilerOptions(compiler) {
|
|
40
|
+
if (compiler.options && compiler.options.output) {
|
|
41
|
+
//todo, need to change / remove
|
|
42
|
+
compiler.options.output.importMetaName = 'remoteContainerRegistry';
|
|
43
|
+
}
|
|
44
|
+
const chunkFileName = compiler.options?.output?.chunkFilename;
|
|
45
|
+
const uniqueName = compiler?.options?.output?.uniqueName || this._options.name;
|
|
46
|
+
if (typeof chunkFileName === 'string' &&
|
|
47
|
+
uniqueName &&
|
|
48
|
+
!chunkFileName.includes(uniqueName)) {
|
|
49
|
+
const suffix = `-[chunkhash].js`;
|
|
50
|
+
compiler.options.output.chunkFilename = chunkFileName.replace('.js', suffix);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
getModuleFederationPlugin(compiler, webpack) {
|
|
54
|
+
let ModuleFederationPlugin;
|
|
55
|
+
try {
|
|
56
|
+
return require('@module-federation/enhanced').ModuleFederationPlugin;
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
console.error("Can't find @module-federation/enhanced, falling back to webpack ModuleFederationPlugin, this may not work");
|
|
60
|
+
if (this.context.ModuleFederationPlugin) {
|
|
61
|
+
ModuleFederationPlugin = this.context.ModuleFederationPlugin;
|
|
62
|
+
}
|
|
63
|
+
else if (webpack &&
|
|
64
|
+
webpack.container &&
|
|
65
|
+
webpack.container.ModuleFederationPlugin) {
|
|
66
|
+
ModuleFederationPlugin = webpack.container.ModuleFederationPlugin;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
ModuleFederationPlugin = require('webpack/lib/container/ModuleFederationPlugin');
|
|
70
|
+
}
|
|
71
|
+
return ModuleFederationPlugin;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.default = NodeFederationPlugin;
|
|
76
|
+
//# sourceMappingURL=NodeFederationPlugin.js.map
|
|
@@ -0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ACD,MAAM,aAAa,GAAG,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,aAAa,CAAC;QAC9D,MAAM,UAAU,GACd,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;QAC9D,IACE,OAAO,aAAa,KAAK,QAAQ;YACjC,UAAU;YACV,CAAC,aAAa,CAAC,QAAQ,CAAC,UAAU,CAAC,EACnC;YACA,MAAM,MAAM,GAAG,iBAAiB,CAAC;YACjC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,aAAa,GAAG,aAAa,CAAC,OAAO,CAC3D,KAAK,EACL,MAAM,CACP,CAAC;SACH;IACH,CAAC;IAEO,yBAAyB,CAAC,QAAkB,EAAE,OAAY;QAChE,IAAI,sBAAsB,CAAC;QAC3B,IAAI;YACF,OAAO,OAAO,CAAC,6BAA6B,CAAC,CAAC,sBAAsB,CAAC;SACtE;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,KAAK,CACX,2GAA2G,CAC5G,CAAC;YACF,IAAI,IAAI,CAAC,OAAO,CAAC,sBAAsB,EAAE;gBACvC,sBAAsB,GAAG,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC;aAC9D;iBAAM,IACL,OAAO;gBACP,OAAO,CAAC,SAAS;gBACjB,OAAO,CAAC,SAAS,CAAC,sBAAsB,EACxC;gBACA,sBAAsB,GAAG,OAAO,CAAC,SAAS,CAAC,sBAAsB,CAAC;aACnE;iBAAM;gBACL,sBAAsB,GAAG,OAAO,CAAC,8CAA8C,CAAC,CAAC;aAClF;YACD,OAAO,sBAAsB,CAAC;SAC/B;IACH,CAAC;CACF;AAED,kBAAe,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare const RuntimeModule: typeof import("webpack").RuntimeModule;
|
|
2
|
+
declare class AutoPublicPathRuntimeModule extends RuntimeModule {
|
|
3
|
+
private options;
|
|
4
|
+
constructor(options: any);
|
|
5
|
+
/**
|
|
6
|
+
* @returns {string} runtime code
|
|
7
|
+
*/
|
|
8
|
+
generate(): string;
|
|
9
|
+
}
|
|
10
|
+
export default AutoPublicPathRuntimeModule;
|
|
@@ -0,0 +1,109 @@
|
|
|
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 { RuntimeGlobals, RuntimeModule, Template, javascript } = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack'));
|
|
5
|
+
const { getUndoPath } = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack/lib/util/identifier'));
|
|
6
|
+
class AutoPublicPathRuntimeModule extends RuntimeModule {
|
|
7
|
+
constructor(options) {
|
|
8
|
+
super('publicPath', RuntimeModule.STAGE_BASIC + 1);
|
|
9
|
+
this.options = options;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* @returns {string} runtime code
|
|
13
|
+
*/
|
|
14
|
+
generate() {
|
|
15
|
+
const { compilation } = this;
|
|
16
|
+
const { scriptType, path, publicPath, importMetaName, uniqueName, chunkLoading,
|
|
17
|
+
//@ts-ignore
|
|
18
|
+
} = compilation.outputOptions;
|
|
19
|
+
const getPath = () => compilation?.getPath(publicPath || '', {
|
|
20
|
+
hash: compilation?.hash || 'XXXX',
|
|
21
|
+
});
|
|
22
|
+
// If publicPath is not "auto", return the static value
|
|
23
|
+
// if (publicPath !== 'auto') {
|
|
24
|
+
// const path = getPath();
|
|
25
|
+
// return Template.asString([
|
|
26
|
+
// `${RuntimeGlobals.publicPath} = ${JSON.stringify(path)};`,
|
|
27
|
+
// 'var addProtocol = (url)=> url.startsWith(\'//\') ? \'https:\' + url : url;',
|
|
28
|
+
// `globalThis.currentVmokPublicPath = addProtocol(${RuntimeGlobals.publicPath}) || '/';`,
|
|
29
|
+
// ]);
|
|
30
|
+
// }
|
|
31
|
+
const chunkName = compilation?.getPath(javascript.JavascriptModulesPlugin.getChunkFilenameTemplate(this.chunk, compilation?.outputOptions), {
|
|
32
|
+
chunk: this.chunk,
|
|
33
|
+
contentHashType: 'javascript',
|
|
34
|
+
});
|
|
35
|
+
const undoPath = getUndoPath(chunkName, path, false);
|
|
36
|
+
const ident = Template.toIdentifier(uniqueName || '');
|
|
37
|
+
// Define potential lookup keys
|
|
38
|
+
const potentialLookups = [this.chunk?.name, ident, uniqueName];
|
|
39
|
+
// Generate lookup string using potential keys
|
|
40
|
+
const lookupString = potentialLookups
|
|
41
|
+
.filter(Boolean)
|
|
42
|
+
.map((lookup) => {
|
|
43
|
+
return `remoteReg[${JSON.stringify(lookup)}]`;
|
|
44
|
+
})
|
|
45
|
+
.join(' || ');
|
|
46
|
+
return Template.asString([
|
|
47
|
+
'var scriptUrl;',
|
|
48
|
+
// its an esproxy so nesting into _config directly is not possible
|
|
49
|
+
`
|
|
50
|
+
let remoteContainerRegistry = {
|
|
51
|
+
get url() {
|
|
52
|
+
var remoteReg = globalThis.__remote_scope__ ? globalThis.__remote_scope__._config : {};
|
|
53
|
+
return ${lookupString}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
`,
|
|
57
|
+
['module', 'node', 'async-node', 'require'].includes(scriptType || '') ||
|
|
58
|
+
chunkLoading
|
|
59
|
+
? Template.asString([
|
|
60
|
+
'try {',
|
|
61
|
+
Template.indent([
|
|
62
|
+
`scriptUrl = new Function('return typeof ${importMetaName}.url === "string" ? ${importMetaName}.url : undefined;')();`,
|
|
63
|
+
]),
|
|
64
|
+
'} catch (e) {',
|
|
65
|
+
Template.indent([
|
|
66
|
+
'if (typeof remoteContainerRegistry.url === "string") {',
|
|
67
|
+
Template.indent('scriptUrl = remoteContainerRegistry.url;'),
|
|
68
|
+
'} else if(typeof __filename !== "undefined") {',
|
|
69
|
+
Template.indent('scriptUrl = __filename;'),
|
|
70
|
+
'} else {',
|
|
71
|
+
Template.indent([
|
|
72
|
+
`scriptUrl = ${publicPath !== 'auto'
|
|
73
|
+
? JSON.stringify(getPath())
|
|
74
|
+
: 'undefined'}`,
|
|
75
|
+
]),
|
|
76
|
+
'}',
|
|
77
|
+
]),
|
|
78
|
+
'}',
|
|
79
|
+
])
|
|
80
|
+
: Template.asString([
|
|
81
|
+
`if (${RuntimeGlobals.global}.importScripts) scriptUrl = ${RuntimeGlobals.global}.location + "";`,
|
|
82
|
+
`var document = ${RuntimeGlobals.global}.document;`,
|
|
83
|
+
'if (!scriptUrl && document) {',
|
|
84
|
+
Template.indent([
|
|
85
|
+
'if (document.currentScript)',
|
|
86
|
+
Template.indent('scriptUrl = document.currentScript.src'),
|
|
87
|
+
'if (!scriptUrl) {',
|
|
88
|
+
Template.indent([
|
|
89
|
+
'var scripts = document.getElementsByTagName("script");',
|
|
90
|
+
'if(scripts.length) scriptUrl = scripts[scripts.length - 1].src',
|
|
91
|
+
]),
|
|
92
|
+
'}',
|
|
93
|
+
]),
|
|
94
|
+
'}',
|
|
95
|
+
]),
|
|
96
|
+
'// When supporting server environments where an automatic publicPath is not supported, you must specify an output.publicPath manually via configuration',
|
|
97
|
+
'// or pass an empty string ("") and set the __webpack_public_path__ variable from your code to use your own logic.',
|
|
98
|
+
'if (!scriptUrl) throw new Error("Unable to calculate automatic public path");',
|
|
99
|
+
'scriptUrl = scriptUrl.replace(/#.*$/, "").replace(/\\?.*$/, "").replace(/\\/[^\\/]+$/, "/");',
|
|
100
|
+
!undoPath
|
|
101
|
+
? `${RuntimeGlobals.publicPath} = scriptUrl;`
|
|
102
|
+
: `${RuntimeGlobals.publicPath} = scriptUrl + ${JSON.stringify(undoPath)};`,
|
|
103
|
+
"var addProtocol = (url)=> url.startsWith('//') ? 'https:' + url : url;",
|
|
104
|
+
`globalThis.currentVmokPublicPath = addProtocol(${RuntimeGlobals.publicPath}) || '/';`,
|
|
105
|
+
]);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.default = AutoPublicPathRuntimeModule;
|
|
109
|
+
//# sourceMappingURL=RemotePublicPathRuntimeModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RemotePublicPathRuntimeModule.js","sourceRoot":"","sources":["../../../../../packages/node/src/plugins/RemotePublicPathRuntimeModule.ts"],"names":[],"mappings":";;AAAA,0FAAqF;AACrF,MAAM,EAAE,cAAc,EAAE,aAAa,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,OAAO,CACrE,IAAA,6CAAoB,EAAC,SAAS,CAAC,CACJ,CAAC;AAC9B,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAC7B,IAAA,6CAAoB,EAAC,6BAA6B,CAAC,CACJ,CAAC;AAElD,MAAM,2BAA4B,SAAQ,aAAa;IAGrD,YAAY,OAAY;QACtB,KAAK,CAAC,YAAY,EAAE,aAAa,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC;QACnD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;OAEG;IACM,QAAQ;QACf,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;QAC7B,MAAM,EACJ,UAAU,EACV,IAAI,EACJ,UAAU,EACV,cAAc,EACd,UAAU,EACV,YAAY;QACZ,YAAY;UACb,GAAG,WAAW,CAAC,aAAa,CAAC;QAE9B,MAAM,OAAO,GAAG,GAAG,EAAE,CACnB,WAAW,EAAE,OAAO,CAAC,UAAU,IAAI,EAAE,EAAE;YACrC,IAAI,EAAE,WAAW,EAAE,IAAI,IAAI,MAAM;SAClC,CAAC,CAAC;QACL,uDAAuD;QACvD,+BAA+B;QAC/B,4BAA4B;QAC5B,+BAA+B;QAC/B,iEAAiE;QACjE,oFAAoF;QACpF,8FAA8F;QAC9F,QAAQ;QACR,IAAI;QACJ,MAAM,SAAS,GAAG,WAAW,EAAE,OAAO,CACpC,UAAU,CAAC,uBAAuB,CAAC,wBAAwB,CACzD,IAAI,CAAC,KAAK,EACV,WAAW,EAAE,aAAa,CAC3B,EACD;YACE,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,OAAO,EAAE,CAAC;gCAC3B,CAAC,CAAC,WACN,EAAE;yBACH,CAAC;wBACF,GAAG;qBACJ,CAAC;oBACF,GAAG;iBACJ,CAAC;gBACJ,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;oBAChB,OAAO,cAAc,CAAC,MAAM,+BAA+B,cAAc,CAAC,MAAM,iBAAiB;oBACjG,kBAAkB,cAAc,CAAC,MAAM,YAAY;oBACnD,+BAA+B;oBAC/B,QAAQ,CAAC,MAAM,CAAC;wBACd,6BAA6B;wBAC7B,QAAQ,CAAC,MAAM,CAAC,wCAAwC,CAAC;wBACzD,mBAAmB;wBACnB,QAAQ,CAAC,MAAM,CAAC;4BACd,wDAAwD;4BACxD,gEAAgE;yBACjE,CAAC;wBACF,GAAG;qBACJ,CAAC;oBACF,GAAG;iBACJ,CAAC;YACN,yJAAyJ;YACzJ,oHAAoH;YACpH,+EAA+E;YAC/E,8FAA8F;YAC9F,CAAC,QAAQ;gBACP,CAAC,CAAC,GAAG,cAAc,CAAC,UAAU,eAAe;gBAC7C,CAAC,CAAC,GAAG,cAAc,CAAC,UAAU,kBAAkB,IAAI,CAAC,SAAS,CAC1D,QAAQ,CACT,GAAG;YACR,wEAAwE;YACxE,kDAAkD,cAAc,CAAC,UAAU,WAAW;SACvF,CAAC,CAAC;IACL,CAAC;CACF;AAED,kBAAe,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Compiler, WebpackPluginInstance } from 'webpack';
|
|
2
|
+
import type { ModuleFederationPluginOptions } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Interface for StreamingTargetOptions which extends ModuleFederationPluginOptions
|
|
5
|
+
* @property {string} promiseBaseURI - The base URI for the promise
|
|
6
|
+
* @property {boolean} debug - Flag to enable/disable debug mode
|
|
7
|
+
*/
|
|
8
|
+
interface StreamingTargetOptions extends ModuleFederationPluginOptions {
|
|
9
|
+
promiseBaseURI?: string;
|
|
10
|
+
debug?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Class representing a StreamingTargetPlugin
|
|
14
|
+
*/
|
|
15
|
+
declare class StreamingTargetPlugin implements WebpackPluginInstance {
|
|
16
|
+
private options;
|
|
17
|
+
/**
|
|
18
|
+
* Create a StreamingTargetPlugin
|
|
19
|
+
* @param {StreamingTargetOptions} options - The options for the plugin
|
|
20
|
+
*/
|
|
21
|
+
constructor(options: StreamingTargetOptions);
|
|
22
|
+
/**
|
|
23
|
+
* Apply the plugin to the compiler
|
|
24
|
+
* @param {Compiler} compiler - The webpack compiler
|
|
25
|
+
*/
|
|
26
|
+
apply(compiler: Compiler): void;
|
|
27
|
+
}
|
|
28
|
+
export default StreamingTargetPlugin;
|
|
@@ -0,0 +1,59 @@
|
|
|
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 CommonJsChunkLoadingPlugin_1 = __importDefault(require("./CommonJsChunkLoadingPlugin"));
|
|
7
|
+
/**
|
|
8
|
+
* Class representing a StreamingTargetPlugin
|
|
9
|
+
*/
|
|
10
|
+
class StreamingTargetPlugin {
|
|
11
|
+
/**
|
|
12
|
+
* Create a StreamingTargetPlugin
|
|
13
|
+
* @param {StreamingTargetOptions} options - The options for the plugin
|
|
14
|
+
*/
|
|
15
|
+
constructor(options) {
|
|
16
|
+
this.options = options || {};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Apply the plugin to the compiler
|
|
20
|
+
* @param {Compiler} compiler - The webpack compiler
|
|
21
|
+
*/
|
|
22
|
+
apply(compiler) {
|
|
23
|
+
// When used with Next.js, context is needed to use Next.js webpack
|
|
24
|
+
const { webpack } = compiler;
|
|
25
|
+
compiler.options.output.chunkFormat = 'commonjs';
|
|
26
|
+
if (compiler.options.output.enabledLibraryTypes === undefined) {
|
|
27
|
+
compiler.options.output.enabledLibraryTypes = ['commonjs-module'];
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
compiler.options.output.enabledLibraryTypes.push('commonjs-module');
|
|
31
|
+
}
|
|
32
|
+
compiler.options.output.chunkLoading = 'async-node';
|
|
33
|
+
// Disable default config
|
|
34
|
+
// FIXME: enabledChunkLoadingTypes is of type 'string[] | undefined'
|
|
35
|
+
// Can't use the 'false' value as it isn't the right format,
|
|
36
|
+
// Emptying it out ensures theres no other readFileVm added to webpack runtime
|
|
37
|
+
compiler.options.output.enabledChunkLoadingTypes = [];
|
|
38
|
+
compiler.options.output.environment = {
|
|
39
|
+
...compiler.options.output.environment,
|
|
40
|
+
dynamicImport: true,
|
|
41
|
+
};
|
|
42
|
+
new (webpack?.node?.NodeEnvironmentPlugin ||
|
|
43
|
+
require('webpack/lib/node/NodeEnvironmentPlugin'))({
|
|
44
|
+
infrastructureLogging: compiler.options.infrastructureLogging,
|
|
45
|
+
}).apply(compiler);
|
|
46
|
+
new (webpack?.node?.NodeTargetPlugin ||
|
|
47
|
+
require('webpack/lib/node/NodeTargetPlugin'))().apply(compiler);
|
|
48
|
+
new CommonJsChunkLoadingPlugin_1.default({
|
|
49
|
+
asyncChunkLoading: true,
|
|
50
|
+
name: this.options.name,
|
|
51
|
+
remotes: this.options.remotes,
|
|
52
|
+
baseURI: compiler.options.output.publicPath,
|
|
53
|
+
promiseBaseURI: this.options.promiseBaseURI,
|
|
54
|
+
debug: this.options.debug,
|
|
55
|
+
}).apply(compiler);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.default = StreamingTargetPlugin;
|
|
59
|
+
//# sourceMappingURL=StreamingTargetPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StreamingTargetPlugin.js","sourceRoot":"","sources":["../../../../../packages/node/src/plugins/StreamingTargetPlugin.ts"],"names":[],"mappings":";;;;;AAGA,8FAAsE;AAkBtE;;G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C,CAAC;QAClE,IAAI,oCAA0B,CAAC;YAC7B,iBAAiB,EAAE,IAAI;YACvB,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI;YACvB,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,OAAiC;YACvD,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU;YAC3C,cAAc,EAAE,IAAI,CAAC,OAAO,CAAC,cAAc;YAC3C,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK;SAC1B,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACrB,CAAC;CACF;AAED,kBAAe,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ModuleFederationPluginOptions } from '../types';
|
|
2
|
+
import type { Compiler, container } from 'webpack';
|
|
3
|
+
/**
|
|
4
|
+
* Interface for NodeFederationOptions
|
|
5
|
+
* @property {boolean} isServer - Indicates if the server is running
|
|
6
|
+
* @property {string} [promiseBaseURI] - The base URI for the promise
|
|
7
|
+
* @property {boolean} [debug] - Indicates if debug mode is enabled
|
|
8
|
+
*/
|
|
9
|
+
interface NodeFederationOptions extends ModuleFederationPluginOptions {
|
|
10
|
+
isServer: boolean;
|
|
11
|
+
promiseBaseURI?: string;
|
|
12
|
+
debug?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Interface for NodeFederationContext
|
|
16
|
+
* @property {typeof container.ModuleFederationPlugin} [ModuleFederationPlugin] - The ModuleFederationPlugin from webpack container
|
|
17
|
+
*/
|
|
18
|
+
interface NodeFederationContext {
|
|
19
|
+
ModuleFederationPlugin?: typeof container.ModuleFederationPlugin;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Class representing a UniversalFederationPlugin
|
|
23
|
+
*/
|
|
24
|
+
declare class UniversalFederationPlugin {
|
|
25
|
+
private _options;
|
|
26
|
+
private context;
|
|
27
|
+
private name;
|
|
28
|
+
/**
|
|
29
|
+
* Create a UniversalFederationPlugin
|
|
30
|
+
* @param {NodeFederationOptions} options - The options for the plugin
|
|
31
|
+
* @param {NodeFederationContext} context - The context for the plugin
|
|
32
|
+
*/
|
|
33
|
+
constructor(options: NodeFederationOptions, context: NodeFederationContext);
|
|
34
|
+
/**
|
|
35
|
+
* Apply the plugin to the compiler
|
|
36
|
+
* @param {Compiler} compiler - The webpack compiler
|
|
37
|
+
*/
|
|
38
|
+
apply(compiler: Compiler): void;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Exporting UniversalFederationPlugin as default
|
|
42
|
+
*/
|
|
43
|
+
export default UniversalFederationPlugin;
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
/**
|
|
7
|
+
* Importing necessary plugins and types
|
|
8
|
+
*/
|
|
9
|
+
const StreamingTargetPlugin_1 = __importDefault(require("./StreamingTargetPlugin"));
|
|
10
|
+
const NodeFederationPlugin_1 = __importDefault(require("./NodeFederationPlugin"));
|
|
11
|
+
const enhanced_1 = require("@module-federation/enhanced");
|
|
12
|
+
const normalize_webpack_path_1 = require("@module-federation/sdk/normalize-webpack-path");
|
|
13
|
+
/**
|
|
14
|
+
* Class representing a UniversalFederationPlugin
|
|
15
|
+
*/
|
|
16
|
+
class UniversalFederationPlugin {
|
|
17
|
+
/**
|
|
18
|
+
* Create a UniversalFederationPlugin
|
|
19
|
+
* @param {NodeFederationOptions} options - The options for the plugin
|
|
20
|
+
* @param {NodeFederationContext} context - The context for the plugin
|
|
21
|
+
*/
|
|
22
|
+
constructor(options, context) {
|
|
23
|
+
this._options = options || {};
|
|
24
|
+
this.context = context || {};
|
|
25
|
+
this.name = 'ModuleFederationPlugin';
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Apply the plugin to the compiler
|
|
29
|
+
* @param {Compiler} compiler - The webpack compiler
|
|
30
|
+
*/
|
|
31
|
+
apply(compiler) {
|
|
32
|
+
const { isServer, debug, ...options } = this._options;
|
|
33
|
+
const { webpack } = compiler;
|
|
34
|
+
if (!process.env['FEDERATION_WEBPACK_PATH']) {
|
|
35
|
+
process.env['FEDERATION_WEBPACK_PATH'] = (0, normalize_webpack_path_1.getWebpackPath)(compiler);
|
|
36
|
+
}
|
|
37
|
+
if (isServer ||
|
|
38
|
+
compiler.options.name === 'server' ||
|
|
39
|
+
compiler.options.target === 'node' ||
|
|
40
|
+
compiler.options.target === 'async-node') {
|
|
41
|
+
new NodeFederationPlugin_1.default(options, this.context).apply(compiler);
|
|
42
|
+
new StreamingTargetPlugin_1.default({ ...options, debug }).apply(compiler);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
new enhanced_1.ModuleFederationPlugin(options).apply(compiler);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Exporting UniversalFederationPlugin as default
|
|
51
|
+
*/
|
|
52
|
+
exports.default = UniversalFederationPlugin;
|
|
53
|
+
//# sourceMappingURL=UniversalFederationPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UniversalFederationPlugin.js","sourceRoot":"","sources":["../../../../../packages/node/src/plugins/UniversalFederationPlugin.ts"],"names":[],"mappings":";;;;;AAAA;;GAEG;AACH,oFAA4D;AAC5D,kFAA0D;AAC1D,0DAAqE;AAGrE,0FAGuD;AAsBvD;;GAEG;AACH,MAAM,yBAAyB;IAK7B;;;;OAIG;IACH,YAAY,OAA8B,EAAE,OAA8B;QACxE,IAAI,CAAC,QAAQ,GAAG,OAAO,IAAK,EAA4B,CAAC;QACzD,IAAI,CAAC,OAAO,GAAG,OAAO,IAAK,EAA4B,CAAC;QACxD,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACvC,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,QAAkB;QACtB,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,OAAO,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC;QACtD,MAAM,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAC;QAC7B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,EAAE;YAC3C,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,GAAG,IAAA,uCAAc,EAAC,QAAQ,CAAC,CAAC;SACnE;QACD,IACE,QAAQ;YACR,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAK,QAAQ;YAClC,QAAQ,CAAC,OAAO,CAAC,MAAM,KAAK,MAAM;YAClC,QAAQ,CAAC,OAAO,CAAC,MAAM,KAAK,YAAY,EACxC;YACA,IAAI,8BAAoB,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;YAChE,IAAI,+BAAqB,CAAC,EAAE,GAAG,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;SAClE;aAAM;YACL,IAAI,iCAAsB,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;SACrD;IACH,CAAC;CACF;AAED;;GAEG;AACH,kBAAe,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Chunk, ChunkGraph } from 'webpack';
|
|
2
|
+
/**
|
|
3
|
+
* Generates the hot module replacement (HMR) code.
|
|
4
|
+
* @param {boolean} withHmr - Flag indicating whether HMR is enabled.
|
|
5
|
+
* @param {string} rootOutputDir - The root output directory.
|
|
6
|
+
* @returns {string} - The generated HMR code.
|
|
7
|
+
*/
|
|
8
|
+
export declare function generateHmrCode(withHmr: boolean, rootOutputDir: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Retrieves the initial chunk IDs.
|
|
11
|
+
* @param {Chunk} chunk - The chunk object.
|
|
12
|
+
* @param {ChunkGraph} chunkGraph - The chunk graph object.
|
|
13
|
+
* @param {any} chunkHasJs - Function to check if a chunk has JavaScript.
|
|
14
|
+
* @returns {Set} - The set of initial chunk IDs.
|
|
15
|
+
*/
|
|
16
|
+
export declare function getInitialChunkIds(chunk: Chunk, chunkGraph: ChunkGraph, chunkHasJs: any): Set<string | number>;
|
|
17
|
+
/**
|
|
18
|
+
* Generates the loading code for chunks.
|
|
19
|
+
* @param {boolean} withLoading - Flag indicating whether chunk loading is enabled.
|
|
20
|
+
* @param {string} fn - The function name.
|
|
21
|
+
* @param {any} hasJsMatcher - Function to check if a chunk has JavaScript.
|
|
22
|
+
* @param {string} rootOutputDir - The root output directory.
|
|
23
|
+
* @param {Record<string, string>} remotes - The remotes object.
|
|
24
|
+
* @param {string | undefined} name - The name of the chunk.
|
|
25
|
+
* @returns {string} - The generated loading code.
|
|
26
|
+
*/
|
|
27
|
+
export declare function generateLoadingCode(withLoading: boolean, fn: string, hasJsMatcher: any, rootOutputDir: string, remotes: Record<string, string>, name: string | undefined): string;
|
|
28
|
+
/**
|
|
29
|
+
* Generates the HMR manifest code.
|
|
30
|
+
* @param {boolean} withHmrManifest - Flag indicating whether HMR manifest is enabled.
|
|
31
|
+
* @param {string} rootOutputDir - The root output directory.
|
|
32
|
+
* @returns {string} - The generated HMR manifest code.
|
|
33
|
+
*/
|
|
34
|
+
export declare function generateHmrManifestCode(withHmrManifest: boolean, rootOutputDir: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Handles the on chunk load event.
|
|
37
|
+
* @param {boolean} withOnChunkLoad - Flag indicating whether on chunk load event is enabled.
|
|
38
|
+
* @param {any} runtimeTemplate - The runtime template.
|
|
39
|
+
* @returns {string} - The generated on chunk load event handler.
|
|
40
|
+
*/
|
|
41
|
+
export declare function handleOnChunkLoad(withOnChunkLoad: boolean, runtimeTemplate: any): string;
|
|
42
|
+
/**
|
|
43
|
+
* Generates the load script for server-side execution. This function creates a script that loads a remote module
|
|
44
|
+
* and executes it in the current context. It supports both browser and Node.js environments.
|
|
45
|
+
* @param {any} runtimeTemplate - The runtime template used to generate the load script.
|
|
46
|
+
* @returns {string} - The generated load script.
|
|
47
|
+
*/
|
|
48
|
+
export declare function generateLoadScript(runtimeTemplate: any): string;
|
|
49
|
+
export declare function generateInstallChunk(runtimeTemplate: any, withOnChunkLoad: boolean): string;
|
|
50
|
+
export declare function generateExternalInstallChunkCode(withExternalInstallChunk: boolean, debug: boolean | undefined): string;
|