@module-federation/vite 1.0.0-alpha-4a73cd4 → 1.0.0-alpha-10e1f83
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/index.cjs +9 -7
- package/lib/index.esm.js +9 -7
- package/lib/index.modern.js +10 -6
- package/lib/index.umd.js +9 -7
- package/lib/virtualModules/virtualRemoteEntry.d.ts +3 -1
- package/package.json +6 -6
package/lib/index.cjs
CHANGED
|
@@ -268,7 +268,7 @@ function getLoadShareModulePath(pkg) {
|
|
|
268
268
|
return path.resolve(emptyNpmDir, filename);
|
|
269
269
|
}
|
|
270
270
|
function writeLoadShareModule(pkg, shareItem, command) {
|
|
271
|
-
fs.writeFileSync(getLoadShareModulePath(pkg), "\n const {loadShare} = require(\"@module-federation/runtime\")\n const res = loadShare(" + JSON.stringify(pkg) + ", {\n customShareInfo: {shareConfig:{\n singleton: " + shareItem.shareConfig.singleton + ",\n strictVersion: " + shareItem.shareConfig.strictVersion + ",\n requiredVersion: " + JSON.stringify(shareItem.shareConfig.requiredVersion) + "\n }}})\n const exportModule = " + (command !== "build" ? "/*mf top-level-await placeholder replacement mf*/" : "await ") + "res.then(factory => factory())\n module.exports = exportModule\n ");
|
|
271
|
+
fs.writeFileSync(getLoadShareModulePath(pkg), "\n // dev uses dynamic import to separate chunks\n " + (command !== "build" ? ";() => import(" + JSON.stringify(pkg) + ").catch(() => {});" : '') + "\n const {loadShare} = require(\"@module-federation/runtime\")\n const res = loadShare(" + JSON.stringify(pkg) + ", {\n customShareInfo: {shareConfig:{\n singleton: " + shareItem.shareConfig.singleton + ",\n strictVersion: " + shareItem.shareConfig.strictVersion + ",\n requiredVersion: " + JSON.stringify(shareItem.shareConfig.requiredVersion) + "\n }}})\n const exportModule = " + (command !== "build" ? "/*mf top-level-await placeholder replacement mf*/" : "await ") + "res.then(factory => factory())\n module.exports = exportModule\n ");
|
|
272
272
|
}
|
|
273
273
|
function npmPackageNameToFileName(packageName) {
|
|
274
274
|
// 1. 去掉包名前的 "@"
|
|
@@ -299,7 +299,8 @@ function generateRemoteEntry(options) {
|
|
|
299
299
|
return item[0] + "()";
|
|
300
300
|
}).join(', ') + "]\n });\n initRes.initShareScopeMap('" + options.shareScope + "', shared);\n return initRes\n }\n\n function getExposes(moduleName) {\n if (!(moduleName in exposesMap)) throw new Error(`Module ${moduleName} does not exist in container.`)\n return (exposesMap[moduleName])().then(res => () => res)\n }\n export {\n init,\n getExposes as get\n }\n ";
|
|
301
301
|
}
|
|
302
|
-
var
|
|
302
|
+
var WRAP_REMOTE_ENTRY_QUERY_STR = "__mf__wrapRemoteEntry__";
|
|
303
|
+
var WRAP_REMOTE_ENTRY_PATH = emptyPath + '?' + WRAP_REMOTE_ENTRY_QUERY_STR;
|
|
303
304
|
function generateWrapRemoteEntry() {
|
|
304
305
|
return "\n import {init, get} from \"" + REMOTE_ENTRY_ID + "\"\n export {init, get}\n ";
|
|
305
306
|
}
|
|
@@ -307,7 +308,8 @@ function generateWrapRemoteEntry() {
|
|
|
307
308
|
* Inject entry file, automatically init when used as host,
|
|
308
309
|
* and will not inject remoteEntry
|
|
309
310
|
*/
|
|
310
|
-
var
|
|
311
|
+
var HOST_AUTO_INIT_QUERY_STR = "__mf__isHostInit";
|
|
312
|
+
var HOST_AUTO_INIT_PATH = emptyPath + '?' + HOST_AUTO_INIT_QUERY_STR;
|
|
311
313
|
function generateWrapHostInit() {
|
|
312
314
|
return "\n import {init} from \"" + REMOTE_ENTRY_ID + "\"\n init()\n ";
|
|
313
315
|
}
|
|
@@ -330,13 +332,13 @@ function pluginProxyRemoteEntry () {
|
|
|
330
332
|
transform: function transform(code, id) {
|
|
331
333
|
try {
|
|
332
334
|
if (!filter$1(id)) return Promise.resolve();
|
|
333
|
-
if (id
|
|
335
|
+
if (id.includes(REMOTE_ENTRY_ID)) {
|
|
334
336
|
return Promise.resolve(generateRemoteEntry(getNormalizeModuleFederationOptions()));
|
|
335
337
|
}
|
|
336
|
-
if (id.includes(
|
|
338
|
+
if (id.includes(WRAP_REMOTE_ENTRY_QUERY_STR)) {
|
|
337
339
|
return Promise.resolve(generateWrapRemoteEntry());
|
|
338
340
|
}
|
|
339
|
-
if (id.includes(
|
|
341
|
+
if (id.includes(HOST_AUTO_INIT_QUERY_STR)) {
|
|
340
342
|
return Promise.resolve(generateWrapHostInit());
|
|
341
343
|
}
|
|
342
344
|
return Promise.resolve();
|
|
@@ -591,7 +593,7 @@ function federation(mfUserOptions) {
|
|
|
591
593
|
fileName: filename
|
|
592
594
|
}), addEntry({
|
|
593
595
|
entryName: 'hostInit',
|
|
594
|
-
entryPath:
|
|
596
|
+
entryPath: HOST_AUTO_INIT_PATH
|
|
595
597
|
}), [pluginProxyRemoteEntry(), pluginProxyRemotes(options)], proxySharedModule({
|
|
596
598
|
shared: shared
|
|
597
599
|
}), [{
|
package/lib/index.esm.js
CHANGED
|
@@ -246,7 +246,7 @@ function getLoadShareModulePath(pkg) {
|
|
|
246
246
|
return resolve(emptyNpmDir, filename);
|
|
247
247
|
}
|
|
248
248
|
function writeLoadShareModule(pkg, shareItem, command) {
|
|
249
|
-
writeFileSync(getLoadShareModulePath(pkg), "\n const {loadShare} = require(\"@module-federation/runtime\")\n const res = loadShare(" + JSON.stringify(pkg) + ", {\n customShareInfo: {shareConfig:{\n singleton: " + shareItem.shareConfig.singleton + ",\n strictVersion: " + shareItem.shareConfig.strictVersion + ",\n requiredVersion: " + JSON.stringify(shareItem.shareConfig.requiredVersion) + "\n }}})\n const exportModule = " + (command !== "build" ? "/*mf top-level-await placeholder replacement mf*/" : "await ") + "res.then(factory => factory())\n module.exports = exportModule\n ");
|
|
249
|
+
writeFileSync(getLoadShareModulePath(pkg), "\n // dev uses dynamic import to separate chunks\n " + (command !== "build" ? ";() => import(" + JSON.stringify(pkg) + ").catch(() => {});" : '') + "\n const {loadShare} = require(\"@module-federation/runtime\")\n const res = loadShare(" + JSON.stringify(pkg) + ", {\n customShareInfo: {shareConfig:{\n singleton: " + shareItem.shareConfig.singleton + ",\n strictVersion: " + shareItem.shareConfig.strictVersion + ",\n requiredVersion: " + JSON.stringify(shareItem.shareConfig.requiredVersion) + "\n }}})\n const exportModule = " + (command !== "build" ? "/*mf top-level-await placeholder replacement mf*/" : "await ") + "res.then(factory => factory())\n module.exports = exportModule\n ");
|
|
250
250
|
}
|
|
251
251
|
function npmPackageNameToFileName(packageName) {
|
|
252
252
|
// 1. 去掉包名前的 "@"
|
|
@@ -277,7 +277,8 @@ function generateRemoteEntry(options) {
|
|
|
277
277
|
return item[0] + "()";
|
|
278
278
|
}).join(', ') + "]\n });\n initRes.initShareScopeMap('" + options.shareScope + "', shared);\n return initRes\n }\n\n function getExposes(moduleName) {\n if (!(moduleName in exposesMap)) throw new Error(`Module ${moduleName} does not exist in container.`)\n return (exposesMap[moduleName])().then(res => () => res)\n }\n export {\n init,\n getExposes as get\n }\n ";
|
|
279
279
|
}
|
|
280
|
-
var
|
|
280
|
+
var WRAP_REMOTE_ENTRY_QUERY_STR = "__mf__wrapRemoteEntry__";
|
|
281
|
+
var WRAP_REMOTE_ENTRY_PATH = emptyPath + '?' + WRAP_REMOTE_ENTRY_QUERY_STR;
|
|
281
282
|
function generateWrapRemoteEntry() {
|
|
282
283
|
return "\n import {init, get} from \"" + REMOTE_ENTRY_ID + "\"\n export {init, get}\n ";
|
|
283
284
|
}
|
|
@@ -285,7 +286,8 @@ function generateWrapRemoteEntry() {
|
|
|
285
286
|
* Inject entry file, automatically init when used as host,
|
|
286
287
|
* and will not inject remoteEntry
|
|
287
288
|
*/
|
|
288
|
-
var
|
|
289
|
+
var HOST_AUTO_INIT_QUERY_STR = "__mf__isHostInit";
|
|
290
|
+
var HOST_AUTO_INIT_PATH = emptyPath + '?' + HOST_AUTO_INIT_QUERY_STR;
|
|
289
291
|
function generateWrapHostInit() {
|
|
290
292
|
return "\n import {init} from \"" + REMOTE_ENTRY_ID + "\"\n init()\n ";
|
|
291
293
|
}
|
|
@@ -308,13 +310,13 @@ function pluginProxyRemoteEntry () {
|
|
|
308
310
|
transform: function transform(code, id) {
|
|
309
311
|
try {
|
|
310
312
|
if (!filter$1(id)) return Promise.resolve();
|
|
311
|
-
if (id
|
|
313
|
+
if (id.includes(REMOTE_ENTRY_ID)) {
|
|
312
314
|
return Promise.resolve(generateRemoteEntry(getNormalizeModuleFederationOptions()));
|
|
313
315
|
}
|
|
314
|
-
if (id.includes(
|
|
316
|
+
if (id.includes(WRAP_REMOTE_ENTRY_QUERY_STR)) {
|
|
315
317
|
return Promise.resolve(generateWrapRemoteEntry());
|
|
316
318
|
}
|
|
317
|
-
if (id.includes(
|
|
319
|
+
if (id.includes(HOST_AUTO_INIT_QUERY_STR)) {
|
|
318
320
|
return Promise.resolve(generateWrapHostInit());
|
|
319
321
|
}
|
|
320
322
|
return Promise.resolve();
|
|
@@ -569,7 +571,7 @@ function federation(mfUserOptions) {
|
|
|
569
571
|
fileName: filename
|
|
570
572
|
}), addEntry({
|
|
571
573
|
entryName: 'hostInit',
|
|
572
|
-
entryPath:
|
|
574
|
+
entryPath: HOST_AUTO_INIT_PATH
|
|
573
575
|
}), [pluginProxyRemoteEntry(), pluginProxyRemotes(options)], proxySharedModule({
|
|
574
576
|
shared: shared
|
|
575
577
|
}), [{
|
package/lib/index.modern.js
CHANGED
|
@@ -263,6 +263,8 @@ function getLoadShareModulePath(pkg) {
|
|
|
263
263
|
}
|
|
264
264
|
function writeLoadShareModule(pkg, shareItem, command) {
|
|
265
265
|
writeFileSync(getLoadShareModulePath(pkg), `
|
|
266
|
+
// dev uses dynamic import to separate chunks
|
|
267
|
+
${command !== "build" ? `;() => import(${JSON.stringify(pkg)}).catch(() => {});` : ''}
|
|
266
268
|
const {loadShare} = require("@module-federation/runtime")
|
|
267
269
|
const res = loadShare(${JSON.stringify(pkg)}, {
|
|
268
270
|
customShareInfo: {shareConfig:{
|
|
@@ -367,7 +369,8 @@ function generateRemoteEntry(options) {
|
|
|
367
369
|
}
|
|
368
370
|
`;
|
|
369
371
|
}
|
|
370
|
-
const
|
|
372
|
+
const WRAP_REMOTE_ENTRY_QUERY_STR = "__mf__wrapRemoteEntry__";
|
|
373
|
+
const WRAP_REMOTE_ENTRY_PATH = emptyPath + '?' + WRAP_REMOTE_ENTRY_QUERY_STR;
|
|
371
374
|
function generateWrapRemoteEntry() {
|
|
372
375
|
return `
|
|
373
376
|
import {init, get} from "${REMOTE_ENTRY_ID}"
|
|
@@ -378,7 +381,8 @@ function generateWrapRemoteEntry() {
|
|
|
378
381
|
* Inject entry file, automatically init when used as host,
|
|
379
382
|
* and will not inject remoteEntry
|
|
380
383
|
*/
|
|
381
|
-
const
|
|
384
|
+
const HOST_AUTO_INIT_QUERY_STR = "__mf__isHostInit";
|
|
385
|
+
const HOST_AUTO_INIT_PATH = emptyPath + '?' + HOST_AUTO_INIT_QUERY_STR;
|
|
382
386
|
function generateWrapHostInit() {
|
|
383
387
|
return `
|
|
384
388
|
import {init} from "${REMOTE_ENTRY_ID}"
|
|
@@ -403,13 +407,13 @@ function pluginProxyRemoteEntry () {
|
|
|
403
407
|
},
|
|
404
408
|
async transform(code, id) {
|
|
405
409
|
if (!filter$1(id)) return;
|
|
406
|
-
if (id
|
|
410
|
+
if (id.includes(REMOTE_ENTRY_ID)) {
|
|
407
411
|
return generateRemoteEntry(getNormalizeModuleFederationOptions());
|
|
408
412
|
}
|
|
409
|
-
if (id.includes(
|
|
413
|
+
if (id.includes(WRAP_REMOTE_ENTRY_QUERY_STR)) {
|
|
410
414
|
return generateWrapRemoteEntry();
|
|
411
415
|
}
|
|
412
|
-
if (id.includes(
|
|
416
|
+
if (id.includes(HOST_AUTO_INIT_QUERY_STR)) {
|
|
413
417
|
return generateWrapHostInit();
|
|
414
418
|
}
|
|
415
419
|
}
|
|
@@ -677,7 +681,7 @@ function federation(mfUserOptions) {
|
|
|
677
681
|
fileName: filename
|
|
678
682
|
}), ...addEntry({
|
|
679
683
|
entryName: 'hostInit',
|
|
680
|
-
entryPath:
|
|
684
|
+
entryPath: HOST_AUTO_INIT_PATH
|
|
681
685
|
}), pluginProxyRemoteEntry(), pluginProxyRemotes(options), ...proxySharedModule({
|
|
682
686
|
shared
|
|
683
687
|
}), {
|
package/lib/index.umd.js
CHANGED
|
@@ -267,7 +267,7 @@
|
|
|
267
267
|
return path.resolve(emptyNpmDir, filename);
|
|
268
268
|
}
|
|
269
269
|
function writeLoadShareModule(pkg, shareItem, command) {
|
|
270
|
-
fs.writeFileSync(getLoadShareModulePath(pkg), "\n const {loadShare} = require(\"@module-federation/runtime\")\n const res = loadShare(" + JSON.stringify(pkg) + ", {\n customShareInfo: {shareConfig:{\n singleton: " + shareItem.shareConfig.singleton + ",\n strictVersion: " + shareItem.shareConfig.strictVersion + ",\n requiredVersion: " + JSON.stringify(shareItem.shareConfig.requiredVersion) + "\n }}})\n const exportModule = " + (command !== "build" ? "/*mf top-level-await placeholder replacement mf*/" : "await ") + "res.then(factory => factory())\n module.exports = exportModule\n ");
|
|
270
|
+
fs.writeFileSync(getLoadShareModulePath(pkg), "\n // dev uses dynamic import to separate chunks\n " + (command !== "build" ? ";() => import(" + JSON.stringify(pkg) + ").catch(() => {});" : '') + "\n const {loadShare} = require(\"@module-federation/runtime\")\n const res = loadShare(" + JSON.stringify(pkg) + ", {\n customShareInfo: {shareConfig:{\n singleton: " + shareItem.shareConfig.singleton + ",\n strictVersion: " + shareItem.shareConfig.strictVersion + ",\n requiredVersion: " + JSON.stringify(shareItem.shareConfig.requiredVersion) + "\n }}})\n const exportModule = " + (command !== "build" ? "/*mf top-level-await placeholder replacement mf*/" : "await ") + "res.then(factory => factory())\n module.exports = exportModule\n ");
|
|
271
271
|
}
|
|
272
272
|
function npmPackageNameToFileName(packageName) {
|
|
273
273
|
// 1. 去掉包名前的 "@"
|
|
@@ -298,7 +298,8 @@
|
|
|
298
298
|
return item[0] + "()";
|
|
299
299
|
}).join(', ') + "]\n });\n initRes.initShareScopeMap('" + options.shareScope + "', shared);\n return initRes\n }\n\n function getExposes(moduleName) {\n if (!(moduleName in exposesMap)) throw new Error(`Module ${moduleName} does not exist in container.`)\n return (exposesMap[moduleName])().then(res => () => res)\n }\n export {\n init,\n getExposes as get\n }\n ";
|
|
300
300
|
}
|
|
301
|
-
var
|
|
301
|
+
var WRAP_REMOTE_ENTRY_QUERY_STR = "__mf__wrapRemoteEntry__";
|
|
302
|
+
var WRAP_REMOTE_ENTRY_PATH = emptyPath + '?' + WRAP_REMOTE_ENTRY_QUERY_STR;
|
|
302
303
|
function generateWrapRemoteEntry() {
|
|
303
304
|
return "\n import {init, get} from \"" + REMOTE_ENTRY_ID + "\"\n export {init, get}\n ";
|
|
304
305
|
}
|
|
@@ -306,7 +307,8 @@
|
|
|
306
307
|
* Inject entry file, automatically init when used as host,
|
|
307
308
|
* and will not inject remoteEntry
|
|
308
309
|
*/
|
|
309
|
-
var
|
|
310
|
+
var HOST_AUTO_INIT_QUERY_STR = "__mf__isHostInit";
|
|
311
|
+
var HOST_AUTO_INIT_PATH = emptyPath + '?' + HOST_AUTO_INIT_QUERY_STR;
|
|
310
312
|
function generateWrapHostInit() {
|
|
311
313
|
return "\n import {init} from \"" + REMOTE_ENTRY_ID + "\"\n init()\n ";
|
|
312
314
|
}
|
|
@@ -329,13 +331,13 @@
|
|
|
329
331
|
transform: function transform(code, id) {
|
|
330
332
|
try {
|
|
331
333
|
if (!filter$1(id)) return Promise.resolve();
|
|
332
|
-
if (id
|
|
334
|
+
if (id.includes(REMOTE_ENTRY_ID)) {
|
|
333
335
|
return Promise.resolve(generateRemoteEntry(getNormalizeModuleFederationOptions()));
|
|
334
336
|
}
|
|
335
|
-
if (id.includes(
|
|
337
|
+
if (id.includes(WRAP_REMOTE_ENTRY_QUERY_STR)) {
|
|
336
338
|
return Promise.resolve(generateWrapRemoteEntry());
|
|
337
339
|
}
|
|
338
|
-
if (id.includes(
|
|
340
|
+
if (id.includes(HOST_AUTO_INIT_QUERY_STR)) {
|
|
339
341
|
return Promise.resolve(generateWrapHostInit());
|
|
340
342
|
}
|
|
341
343
|
return Promise.resolve();
|
|
@@ -590,7 +592,7 @@
|
|
|
590
592
|
fileName: filename
|
|
591
593
|
}), addEntry({
|
|
592
594
|
entryName: 'hostInit',
|
|
593
|
-
entryPath:
|
|
595
|
+
entryPath: HOST_AUTO_INIT_PATH
|
|
594
596
|
}), [pluginProxyRemoteEntry(), pluginProxyRemotes(options)], proxySharedModule({
|
|
595
597
|
shared: shared
|
|
596
598
|
}), [{
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { NormalizedModuleFederationOptions } from "../utils/normalizeModuleFederationOptions";
|
|
2
2
|
export declare const REMOTE_ENTRY_ID = "REMOTE_ENTRY_ID";
|
|
3
3
|
export declare function generateRemoteEntry(options: NormalizedModuleFederationOptions): string;
|
|
4
|
+
export declare const WRAP_REMOTE_ENTRY_QUERY_STR = "__mf__wrapRemoteEntry__";
|
|
4
5
|
export declare const WRAP_REMOTE_ENTRY_PATH: string;
|
|
5
6
|
export declare function generateWrapRemoteEntry(): string;
|
|
6
7
|
/**
|
|
7
8
|
* Inject entry file, automatically init when used as host,
|
|
8
9
|
* and will not inject remoteEntry
|
|
9
10
|
*/
|
|
10
|
-
export declare const
|
|
11
|
+
export declare const HOST_AUTO_INIT_QUERY_STR = "__mf__isHostInit";
|
|
12
|
+
export declare const HOST_AUTO_INIT_PATH: string;
|
|
11
13
|
export declare function generateWrapHostInit(): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/vite",
|
|
3
|
-
"version": "1.0.0-alpha-
|
|
3
|
+
"version": "1.0.0-alpha-10e1f83",
|
|
4
4
|
"description": "Vite plugin for Module Federation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"source": "src/index.ts",
|
|
@@ -38,19 +38,19 @@
|
|
|
38
38
|
"homepage": "https://github.com/module-federation/vite#readme",
|
|
39
39
|
"packageManager": "pnpm@9.1.3",
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@module-federation/runtime": "^0.
|
|
41
|
+
"@module-federation/runtime": "^0.3.5",
|
|
42
42
|
"@rollup/pluginutils": "^5.1.0",
|
|
43
43
|
"an-empty-js-file": "1.0.0",
|
|
44
44
|
"estree-walker": "^2",
|
|
45
|
-
"magic-string": "^0.30.
|
|
45
|
+
"magic-string": "^0.30.11",
|
|
46
46
|
"pathe": "^1.1.2"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"husky": "^8.0.3",
|
|
50
50
|
"microbundle": "^0.15.1",
|
|
51
51
|
"mime-types": "^2.1.35",
|
|
52
|
-
"pretty-quick": "^
|
|
53
|
-
"rimraf": "^
|
|
54
|
-
"vite": "^
|
|
52
|
+
"pretty-quick": "^4.0.0",
|
|
53
|
+
"rimraf": "^6.0.1",
|
|
54
|
+
"vite": "^5.4.0"
|
|
55
55
|
}
|
|
56
56
|
}
|