@module-federation/nextjs-mf 5.3.1 → 5.3.3
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/lib/NextFederationPlugin.js +1064 -34
- package/lib/loaders/UrlNode.js +1 -1
- package/package.json +1 -1
- package/lib/node-plugin/streaming/CommonJsChunkLoadingPlugin.js +0 -86
- package/lib/node-plugin/streaming/LoadFileChunkLoadingRuntimeModule.js +0 -410
- package/lib/node-plugin/streaming/NodeRuntime.js +0 -147
- package/lib/node-plugin/streaming/index.js +0 -44
- package/lib/node-plugin/streaming/loadScript.js +0 -55
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var CommonJsChunkLoadingPlugin = require('./CommonJsChunkLoadingPlugin.js');
|
|
4
|
-
|
|
5
|
-
class NodeSoftwareStreamRuntime {
|
|
6
|
-
constructor(options, context) {
|
|
7
|
-
this.options = options || {};
|
|
8
|
-
this.context = context || {};
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
apply(compiler) {
|
|
12
|
-
if (compiler.options.target) {
|
|
13
|
-
console.warn(
|
|
14
|
-
`target should be set to false while using NodeSoftwareStreamRuntime plugin, actual target: ${compiler.options.target}`
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// When used with Next.js, context is needed to use Next.js webpack
|
|
19
|
-
const { webpack } = compiler;
|
|
20
|
-
|
|
21
|
-
// This will enable CommonJsChunkFormatPlugin
|
|
22
|
-
compiler.options.output.chunkFormat = 'commonjs';
|
|
23
|
-
// This will force async chunk loading
|
|
24
|
-
compiler.options.output.chunkLoading = 'async-node';
|
|
25
|
-
// Disable default config
|
|
26
|
-
compiler.options.output.enabledChunkLoadingTypes = false;
|
|
27
|
-
|
|
28
|
-
new ((webpack && webpack.node && webpack.node.NodeEnvironmentPlugin) ||
|
|
29
|
-
require('webpack/lib/node/NodeEnvironmentPlugin'))({
|
|
30
|
-
infrastructureLogging: compiler.options.infrastructureLogging,
|
|
31
|
-
}).apply(compiler);
|
|
32
|
-
new ((webpack && webpack.node && webpack.node.NodeTargetPlugin) ||
|
|
33
|
-
require('webpack/lib/node/NodeTargetPlugin'))().apply(compiler);
|
|
34
|
-
new CommonJsChunkLoadingPlugin({
|
|
35
|
-
asyncChunkLoading: true,
|
|
36
|
-
name: this.options.name,
|
|
37
|
-
remotes: this.options.remotes,
|
|
38
|
-
baseURI: compiler.options.output.publicPath,
|
|
39
|
-
promiseBaseURI: this.options.promiseBaseURI,
|
|
40
|
-
}).apply(compiler);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
module.exports = NodeSoftwareStreamRuntime;
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* loadScript(baseURI, fileName, cb)
|
|
5
|
-
* loadScript(scriptUrl, cb)
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
var loadScript = `
|
|
9
|
-
function loadScript(url,cb,chunkID) {
|
|
10
|
-
var url;
|
|
11
|
-
var cb = arguments[arguments.length - 1];
|
|
12
|
-
if (typeof cb !== "function") {
|
|
13
|
-
throw new Error("last argument should be a function");
|
|
14
|
-
}
|
|
15
|
-
if (arguments.length === 2) {
|
|
16
|
-
url = arguments[0];
|
|
17
|
-
} else if (arguments.length === 3) {
|
|
18
|
-
url = new URL(arguments[1], arguments[0]).toString();
|
|
19
|
-
} else {
|
|
20
|
-
throw new Error("invalid number of arguments");
|
|
21
|
-
}
|
|
22
|
-
if(global.webpackChunkLoad){
|
|
23
|
-
global.webpackChunkLoad(url).then(function(resp){
|
|
24
|
-
return resp.text();
|
|
25
|
-
}).then(function(rawData){
|
|
26
|
-
cb(null, rawData);
|
|
27
|
-
}).catch(function(err){
|
|
28
|
-
console.error('Federated Chunk load failed', error);
|
|
29
|
-
return cb(error)
|
|
30
|
-
});
|
|
31
|
-
} else {
|
|
32
|
-
//TODO https support
|
|
33
|
-
let request = (url.startsWith('https') ? require('https') : require('http')).get(url, function (resp) {
|
|
34
|
-
if (resp.statusCode === 200) {
|
|
35
|
-
let rawData = '';
|
|
36
|
-
resp.setEncoding('utf8');
|
|
37
|
-
resp.on('data', chunk => {
|
|
38
|
-
rawData += chunk;
|
|
39
|
-
});
|
|
40
|
-
resp.on('end', () => {
|
|
41
|
-
cb(null, rawData);
|
|
42
|
-
});
|
|
43
|
-
} else {
|
|
44
|
-
cb(resp);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
request.on('error', error => {
|
|
48
|
-
console.error('Federated Chunk load failed', error);
|
|
49
|
-
return cb(error)
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
`;
|
|
54
|
-
|
|
55
|
-
module.exports = loadScript;
|