@module-federation/vite 1.1.9 → 1.2.1

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 CHANGED
@@ -1,9 +1,9 @@
1
+ var defu = require('defu');
1
2
  var fs = require('fs');
2
3
  var path = require('pathe');
3
4
  var pluginutils = require('@rollup/pluginutils');
4
5
  var estreeWalker = require('estree-walker');
5
6
  var MagicString = require('magic-string');
6
- var defu = require('defu');
7
7
 
8
8
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
9
 
@@ -25,6 +25,7 @@ function _interopNamespace(e) {
25
25
  return n;
26
26
  }
27
27
 
28
+ var defu__default = /*#__PURE__*/_interopDefaultLegacy(defu);
28
29
  var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
29
30
  var path__namespace = /*#__PURE__*/_interopNamespace(path);
30
31
  var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
@@ -65,14 +66,6 @@ var addEntry = function addEntry(_ref) {
65
66
  devEntryPath = config.base + devEntryPath.replace(/\\\\?/g, '/').replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/^\//, '');
66
67
  },
67
68
  configureServer: function configureServer(server) {
68
- var _server$httpServer;
69
- (_server$httpServer = server.httpServer) == null || _server$httpServer.once == null || _server$httpServer.once('listening', function () {
70
- var _server$config$server = server.config.server,
71
- port = _server$config$server.port,
72
- hostConfig = _server$config$server.host;
73
- var host = typeof hostConfig === 'string' && hostConfig !== '0.0.0.0' ? hostConfig : 'localhost';
74
- fetch("http://" + host + ":" + port + devEntryPath)["catch"](function (e) {});
75
- });
76
69
  server.middlewares.use(function (req, res, next) {
77
70
  if (!fileName) {
78
71
  next();
@@ -683,7 +676,7 @@ function generateRemoteEntry(options) {
683
676
  var HOST_AUTO_INIT_TAG = '__H_A_I__';
684
677
  var hostAutoInitModule = new VirtualModule('hostAutoInit', HOST_AUTO_INIT_TAG);
685
678
  function writeHostAutoInit() {
686
- hostAutoInitModule.writeSync("\n import {init} from \"" + REMOTE_ENTRY_ID + "\"\n init()\n ");
679
+ hostAutoInitModule.writeSync("\n const remoteEntryPromise = import(\"" + REMOTE_ENTRY_ID + "\")\n // __tla only serves as a hack for vite-plugin-top-level-await. \n Promise.resolve(remoteEntryPromise)\n .then(remoteEntry => {\n return Promise.resolve(remoteEntry.__tla)\n .then(remoteEntry.init).catch(remoteEntry.init)\n })\n ");
687
680
  }
688
681
  function getHostAutoInitImportId() {
689
682
  return hostAutoInitModule.getImportId();
@@ -1106,7 +1099,7 @@ function pluginProxyRemoteEntry () {
1106
1099
  if (_command === 'serve') {
1107
1100
  var _viteConfig$server, _viteConfig$server2;
1108
1101
  var host = typeof ((_viteConfig$server = viteConfig.server) == null ? void 0 : _viteConfig$server.host) === 'string' && viteConfig.server.host !== '0.0.0.0' ? viteConfig.server.host : 'localhost';
1109
- return Promise.resolve("\n const {init} = await import(\"//" + host + ":" + ((_viteConfig$server2 = viteConfig.server) == null ? void 0 : _viteConfig$server2.port) + (viteConfig.base + options.filename) + "\")\n init()\n ");
1102
+ return Promise.resolve("\n const origin = window ? window.origin : \"//" + host + ":" + ((_viteConfig$server2 = viteConfig.server) == null ? void 0 : _viteConfig$server2.port) + "\"\n const remoteEntryPromise = await import(origin + \"" + (viteConfig.base + options.filename) + "\")\n // __tla only serves as a hack for vite-plugin-top-level-await. \n Promise.resolve(remoteEntryPromise)\n .then(remoteEntry => {\n return Promise.resolve(remoteEntry.__tla)\n .then(remoteEntry.init).catch(remoteEntry.init)\n })\n ");
1110
1103
  }
1111
1104
  return Promise.resolve(code);
1112
1105
  }
@@ -1221,7 +1214,7 @@ function proxySharedModule(options) {
1221
1214
  writePreBuildLibPath(source);
1222
1215
  addUsedShares(source);
1223
1216
  writeLocalSharedImportMap();
1224
- return this.resolve(loadSharePath);
1217
+ return this.resolve(loadSharePath, importer);
1225
1218
  }
1226
1219
  };
1227
1220
  }));
@@ -1240,7 +1233,7 @@ function proxySharedModule(options) {
1240
1233
  try {
1241
1234
  var _this = this;
1242
1235
  var pkgName = VirtualModule.findModule(PREBUILD_TAG, source).name;
1243
- return Promise.resolve(_this.resolve(pkgName).then(function (item) {
1236
+ return Promise.resolve(_this.resolve(pkgName, importer).then(function (item) {
1244
1237
  return item.id;
1245
1238
  })).then(function (result) {
1246
1239
  if (!result.includes(_config.cacheDir)) {
@@ -1250,7 +1243,7 @@ function proxySharedModule(options) {
1250
1243
  // Fix localSharedImportMap import id
1251
1244
  var _resolve = _this.resolve;
1252
1245
  return Promise.resolve(savePrebuild.get(pkgName)).then(function (_savePrebuild$get) {
1253
- return Promise.resolve(_resolve.call(_this, _savePrebuild$get));
1246
+ return Promise.resolve(_resolve.call(_this, _savePrebuild$get, importer));
1254
1247
  });
1255
1248
  });
1256
1249
  } catch (e) {
@@ -1260,22 +1253,6 @@ function proxySharedModule(options) {
1260
1253
  };
1261
1254
  }));
1262
1255
  }
1263
- }, {
1264
- name: 'watchLocalSharedImportMap',
1265
- apply: 'serve',
1266
- config: function config(_config3) {
1267
- _config3.optimizeDeps = defu.defu(_config3.optimizeDeps, {
1268
- exclude: [getLocalSharedImportMapPath()]
1269
- });
1270
- _config3.server = defu.defu(_config3.server, {
1271
- watch: {
1272
- ignored: []
1273
- }
1274
- });
1275
- var watch = _config3.server.watch;
1276
- watch.ignored = [].concat(watch.ignored);
1277
- watch.ignored.push("!**" + getLocalSharedImportMapPath() + "**");
1278
- }
1279
1256
  }];
1280
1257
  }
1281
1258
 
@@ -1348,6 +1325,11 @@ function federation(mfUserOptions) {
1348
1325
  find: '@module-federation/runtime',
1349
1326
  replacement: options.implementation
1350
1327
  });
1328
+ _config.build = defu__default["default"](_config.build || {}, {
1329
+ commonjsOptions: {
1330
+ strictRequires: 'auto'
1331
+ }
1332
+ });
1351
1333
  (_config$optimizeDeps = _config.optimizeDeps) == null || (_config$optimizeDeps = _config$optimizeDeps.include) == null || _config$optimizeDeps.push('@module-federation/runtime');
1352
1334
  (_config$optimizeDeps2 = _config.optimizeDeps) == null || (_config$optimizeDeps2 = _config$optimizeDeps2.include) == null || _config$optimizeDeps2.push('__mf__virtual');
1353
1335
  (_config$optimizeDeps3 = _config.optimizeDeps) == null || (_config$optimizeDeps3 = _config$optimizeDeps3.needsInterop) == null || _config$optimizeDeps3.push('__mf__virtual');
package/lib/index.esm.js CHANGED
@@ -1,3 +1,4 @@
1
+ import defu from 'defu';
1
2
  import * as fs from 'fs';
2
3
  import { mkdirSync, writeFileSync, existsSync, writeFile } from 'fs';
3
4
  import * as path from 'pathe';
@@ -5,7 +6,6 @@ import path__default, { parse, join, dirname, resolve, relative } from 'pathe';
5
6
  import { createFilter } from '@rollup/pluginutils';
6
7
  import { walk } from 'estree-walker';
7
8
  import MagicString from 'magic-string';
8
- import { defu } from 'defu';
9
9
 
10
10
  function getFirstHtmlEntryFile(entryFiles) {
11
11
  return entryFiles.find(function (file) {
@@ -42,14 +42,6 @@ var addEntry = function addEntry(_ref) {
42
42
  devEntryPath = config.base + devEntryPath.replace(/\\\\?/g, '/').replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/^\//, '');
43
43
  },
44
44
  configureServer: function configureServer(server) {
45
- var _server$httpServer;
46
- (_server$httpServer = server.httpServer) == null || _server$httpServer.once == null || _server$httpServer.once('listening', function () {
47
- var _server$config$server = server.config.server,
48
- port = _server$config$server.port,
49
- hostConfig = _server$config$server.host;
50
- var host = typeof hostConfig === 'string' && hostConfig !== '0.0.0.0' ? hostConfig : 'localhost';
51
- fetch("http://" + host + ":" + port + devEntryPath)["catch"](function (e) {});
52
- });
53
45
  server.middlewares.use(function (req, res, next) {
54
46
  if (!fileName) {
55
47
  next();
@@ -660,7 +652,7 @@ function generateRemoteEntry(options) {
660
652
  var HOST_AUTO_INIT_TAG = '__H_A_I__';
661
653
  var hostAutoInitModule = new VirtualModule('hostAutoInit', HOST_AUTO_INIT_TAG);
662
654
  function writeHostAutoInit() {
663
- hostAutoInitModule.writeSync("\n import {init} from \"" + REMOTE_ENTRY_ID + "\"\n init()\n ");
655
+ hostAutoInitModule.writeSync("\n const remoteEntryPromise = import(\"" + REMOTE_ENTRY_ID + "\")\n // __tla only serves as a hack for vite-plugin-top-level-await. \n Promise.resolve(remoteEntryPromise)\n .then(remoteEntry => {\n return Promise.resolve(remoteEntry.__tla)\n .then(remoteEntry.init).catch(remoteEntry.init)\n })\n ");
664
656
  }
665
657
  function getHostAutoInitImportId() {
666
658
  return hostAutoInitModule.getImportId();
@@ -1083,7 +1075,7 @@ function pluginProxyRemoteEntry () {
1083
1075
  if (_command === 'serve') {
1084
1076
  var _viteConfig$server, _viteConfig$server2;
1085
1077
  var host = typeof ((_viteConfig$server = viteConfig.server) == null ? void 0 : _viteConfig$server.host) === 'string' && viteConfig.server.host !== '0.0.0.0' ? viteConfig.server.host : 'localhost';
1086
- return Promise.resolve("\n const {init} = await import(\"//" + host + ":" + ((_viteConfig$server2 = viteConfig.server) == null ? void 0 : _viteConfig$server2.port) + (viteConfig.base + options.filename) + "\")\n init()\n ");
1078
+ return Promise.resolve("\n const origin = window ? window.origin : \"//" + host + ":" + ((_viteConfig$server2 = viteConfig.server) == null ? void 0 : _viteConfig$server2.port) + "\"\n const remoteEntryPromise = await import(origin + \"" + (viteConfig.base + options.filename) + "\")\n // __tla only serves as a hack for vite-plugin-top-level-await. \n Promise.resolve(remoteEntryPromise)\n .then(remoteEntry => {\n return Promise.resolve(remoteEntry.__tla)\n .then(remoteEntry.init).catch(remoteEntry.init)\n })\n ");
1087
1079
  }
1088
1080
  return Promise.resolve(code);
1089
1081
  }
@@ -1198,7 +1190,7 @@ function proxySharedModule(options) {
1198
1190
  writePreBuildLibPath(source);
1199
1191
  addUsedShares(source);
1200
1192
  writeLocalSharedImportMap();
1201
- return this.resolve(loadSharePath);
1193
+ return this.resolve(loadSharePath, importer);
1202
1194
  }
1203
1195
  };
1204
1196
  }));
@@ -1217,7 +1209,7 @@ function proxySharedModule(options) {
1217
1209
  try {
1218
1210
  var _this = this;
1219
1211
  var pkgName = VirtualModule.findModule(PREBUILD_TAG, source).name;
1220
- return Promise.resolve(_this.resolve(pkgName).then(function (item) {
1212
+ return Promise.resolve(_this.resolve(pkgName, importer).then(function (item) {
1221
1213
  return item.id;
1222
1214
  })).then(function (result) {
1223
1215
  if (!result.includes(_config.cacheDir)) {
@@ -1227,7 +1219,7 @@ function proxySharedModule(options) {
1227
1219
  // Fix localSharedImportMap import id
1228
1220
  var _resolve = _this.resolve;
1229
1221
  return Promise.resolve(savePrebuild.get(pkgName)).then(function (_savePrebuild$get) {
1230
- return Promise.resolve(_resolve.call(_this, _savePrebuild$get));
1222
+ return Promise.resolve(_resolve.call(_this, _savePrebuild$get, importer));
1231
1223
  });
1232
1224
  });
1233
1225
  } catch (e) {
@@ -1237,22 +1229,6 @@ function proxySharedModule(options) {
1237
1229
  };
1238
1230
  }));
1239
1231
  }
1240
- }, {
1241
- name: 'watchLocalSharedImportMap',
1242
- apply: 'serve',
1243
- config: function config(_config3) {
1244
- _config3.optimizeDeps = defu(_config3.optimizeDeps, {
1245
- exclude: [getLocalSharedImportMapPath()]
1246
- });
1247
- _config3.server = defu(_config3.server, {
1248
- watch: {
1249
- ignored: []
1250
- }
1251
- });
1252
- var watch = _config3.server.watch;
1253
- watch.ignored = [].concat(watch.ignored);
1254
- watch.ignored.push("!**" + getLocalSharedImportMapPath() + "**");
1255
- }
1256
1232
  }];
1257
1233
  }
1258
1234
 
@@ -1325,6 +1301,11 @@ function federation(mfUserOptions) {
1325
1301
  find: '@module-federation/runtime',
1326
1302
  replacement: options.implementation
1327
1303
  });
1304
+ _config.build = defu(_config.build || {}, {
1305
+ commonjsOptions: {
1306
+ strictRequires: 'auto'
1307
+ }
1308
+ });
1328
1309
  (_config$optimizeDeps = _config.optimizeDeps) == null || (_config$optimizeDeps = _config$optimizeDeps.include) == null || _config$optimizeDeps.push('@module-federation/runtime');
1329
1310
  (_config$optimizeDeps2 = _config.optimizeDeps) == null || (_config$optimizeDeps2 = _config$optimizeDeps2.include) == null || _config$optimizeDeps2.push('__mf__virtual');
1330
1311
  (_config$optimizeDeps3 = _config.optimizeDeps) == null || (_config$optimizeDeps3 = _config$optimizeDeps3.needsInterop) == null || _config$optimizeDeps3.push('__mf__virtual');
@@ -1,3 +1,4 @@
1
+ import defu from 'defu';
1
2
  import * as fs from 'fs';
2
3
  import { mkdirSync, writeFileSync, existsSync, writeFile } from 'fs';
3
4
  import * as path from 'pathe';
@@ -5,7 +6,6 @@ import path__default, { parse, join, dirname, resolve, relative } from 'pathe';
5
6
  import { createFilter } from '@rollup/pluginutils';
6
7
  import { walk } from 'estree-walker';
7
8
  import MagicString from 'magic-string';
8
- import { defu } from 'defu';
9
9
 
10
10
  function getFirstHtmlEntryFile(entryFiles) {
11
11
  return entryFiles.find(file => file.endsWith('.html'));
@@ -41,15 +41,6 @@ const addEntry = ({
41
41
  devEntryPath = config.base + devEntryPath.replace(/\\\\?/g, '/').replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/^\//, '');
42
42
  },
43
43
  configureServer(server) {
44
- var _server$httpServer;
45
- (_server$httpServer = server.httpServer) == null || _server$httpServer.once == null || _server$httpServer.once('listening', () => {
46
- const {
47
- port,
48
- host: hostConfig
49
- } = server.config.server;
50
- const host = typeof hostConfig === 'string' && hostConfig !== '0.0.0.0' ? hostConfig : 'localhost';
51
- fetch(`http://${host}:${port}${devEntryPath}`).catch(e => {});
52
- });
53
44
  server.middlewares.use((req, res, next) => {
54
45
  if (!fileName) {
55
46
  next();
@@ -753,8 +744,13 @@ const HOST_AUTO_INIT_TAG = '__H_A_I__';
753
744
  const hostAutoInitModule = new VirtualModule('hostAutoInit', HOST_AUTO_INIT_TAG);
754
745
  function writeHostAutoInit() {
755
746
  hostAutoInitModule.writeSync(`
756
- import {init} from "${REMOTE_ENTRY_ID}"
757
- init()
747
+ const remoteEntryPromise = import("${REMOTE_ENTRY_ID}")
748
+ // __tla only serves as a hack for vite-plugin-top-level-await.
749
+ Promise.resolve(remoteEntryPromise)
750
+ .then(remoteEntry => {
751
+ return Promise.resolve(remoteEntry.__tla)
752
+ .then(remoteEntry.init).catch(remoteEntry.init)
753
+ })
758
754
  `);
759
755
  }
760
756
  function getHostAutoInitImportId() {
@@ -1150,8 +1146,14 @@ function pluginProxyRemoteEntry () {
1150
1146
  var _viteConfig$server, _viteConfig$server2;
1151
1147
  const host = typeof ((_viteConfig$server = viteConfig.server) == null ? void 0 : _viteConfig$server.host) === 'string' && viteConfig.server.host !== '0.0.0.0' ? viteConfig.server.host : 'localhost';
1152
1148
  return `
1153
- const {init} = await import("//${host}:${(_viteConfig$server2 = viteConfig.server) == null ? void 0 : _viteConfig$server2.port}${viteConfig.base + options.filename}")
1154
- init()
1149
+ const origin = window ? window.origin : "//${host}:${(_viteConfig$server2 = viteConfig.server) == null ? void 0 : _viteConfig$server2.port}"
1150
+ const remoteEntryPromise = await import(origin + "${viteConfig.base + options.filename}")
1151
+ // __tla only serves as a hack for vite-plugin-top-level-await.
1152
+ Promise.resolve(remoteEntryPromise)
1153
+ .then(remoteEntry => {
1154
+ return Promise.resolve(remoteEntry.__tla)
1155
+ .then(remoteEntry.init).catch(remoteEntry.init)
1156
+ })
1155
1157
  `;
1156
1158
  }
1157
1159
  return code;
@@ -1262,7 +1264,7 @@ function proxySharedModule(options) {
1262
1264
  writePreBuildLibPath(source);
1263
1265
  addUsedShares(source);
1264
1266
  writeLocalSharedImportMap();
1265
- return this.resolve(loadSharePath);
1267
+ return this.resolve(loadSharePath, importer);
1266
1268
  }
1267
1269
  };
1268
1270
  }));
@@ -1279,33 +1281,17 @@ function proxySharedModule(options) {
1279
1281
  replacement: '$1',
1280
1282
  async customResolver(source, importer) {
1281
1283
  const pkgName = VirtualModule.findModule(PREBUILD_TAG, source).name;
1282
- const result = await this.resolve(pkgName).then(item => item.id);
1284
+ const result = await this.resolve(pkgName, importer).then(item => item.id);
1283
1285
  if (!result.includes(_config.cacheDir)) {
1284
1286
  // save pre-bunding module id
1285
1287
  savePrebuild.set(pkgName, Promise.resolve(result));
1286
1288
  }
1287
1289
  // Fix localSharedImportMap import id
1288
- return await this.resolve(await savePrebuild.get(pkgName));
1290
+ return await this.resolve(await savePrebuild.get(pkgName), importer);
1289
1291
  }
1290
1292
  };
1291
1293
  }));
1292
1294
  }
1293
- }, {
1294
- name: 'watchLocalSharedImportMap',
1295
- apply: 'serve',
1296
- config(config) {
1297
- config.optimizeDeps = defu(config.optimizeDeps, {
1298
- exclude: [getLocalSharedImportMapPath()]
1299
- });
1300
- config.server = defu(config.server, {
1301
- watch: {
1302
- ignored: []
1303
- }
1304
- });
1305
- const watch = config.server.watch;
1306
- watch.ignored = [].concat(watch.ignored);
1307
- watch.ignored.push(`!**${getLocalSharedImportMapPath()}**`);
1308
- }
1309
1295
  }];
1310
1296
  }
1311
1297
 
@@ -1387,6 +1373,11 @@ function federation(mfUserOptions) {
1387
1373
  find: '@module-federation/runtime',
1388
1374
  replacement: options.implementation
1389
1375
  });
1376
+ config.build = defu(config.build || {}, {
1377
+ commonjsOptions: {
1378
+ strictRequires: 'auto'
1379
+ }
1380
+ });
1390
1381
  (_config$optimizeDeps = config.optimizeDeps) == null || (_config$optimizeDeps = _config$optimizeDeps.include) == null || _config$optimizeDeps.push('@module-federation/runtime');
1391
1382
  (_config$optimizeDeps2 = config.optimizeDeps) == null || (_config$optimizeDeps2 = _config$optimizeDeps2.include) == null || _config$optimizeDeps2.push('__mf__virtual');
1392
1383
  (_config$optimizeDeps3 = config.optimizeDeps) == null || (_config$optimizeDeps3 = _config$optimizeDeps3.needsInterop) == null || _config$optimizeDeps3.push('__mf__virtual');
package/lib/index.umd.js CHANGED
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('fs'), require('pathe'), require('@rollup/pluginutils'), require('estree-walker'), require('magic-string'), require('defu')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'fs', 'pathe', '@rollup/pluginutils', 'estree-walker', 'magic-string', 'defu'], factory) :
4
- (global = global || self, factory(global.vite = {}, global.fs, global.pathe, global.pluginutils, global.estreeWalker, global.magicString, global.defu));
5
- })(this, (function (exports, fs, path, pluginutils, estreeWalker, MagicString, defu) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('defu'), require('fs'), require('pathe'), require('@rollup/pluginutils'), require('estree-walker'), require('magic-string')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'defu', 'fs', 'pathe', '@rollup/pluginutils', 'estree-walker', 'magic-string'], factory) :
4
+ (global = global || self, factory(global.vite = {}, global.defu, global.fs, global.pathe, global.pluginutils, global.estreeWalker, global.magicString));
5
+ })(this, (function (exports, defu, fs, path, pluginutils, estreeWalker, MagicString) {
6
6
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
7
7
 
8
8
  function _interopNamespace(e) {
@@ -23,6 +23,7 @@
23
23
  return n;
24
24
  }
25
25
 
26
+ var defu__default = /*#__PURE__*/_interopDefaultLegacy(defu);
26
27
  var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
27
28
  var path__namespace = /*#__PURE__*/_interopNamespace(path);
28
29
  var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
@@ -63,14 +64,6 @@
63
64
  devEntryPath = config.base + devEntryPath.replace(/\\\\?/g, '/').replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/^\//, '');
64
65
  },
65
66
  configureServer: function configureServer(server) {
66
- var _server$httpServer;
67
- (_server$httpServer = server.httpServer) == null || _server$httpServer.once == null || _server$httpServer.once('listening', function () {
68
- var _server$config$server = server.config.server,
69
- port = _server$config$server.port,
70
- hostConfig = _server$config$server.host;
71
- var host = typeof hostConfig === 'string' && hostConfig !== '0.0.0.0' ? hostConfig : 'localhost';
72
- fetch("http://" + host + ":" + port + devEntryPath)["catch"](function (e) {});
73
- });
74
67
  server.middlewares.use(function (req, res, next) {
75
68
  if (!fileName) {
76
69
  next();
@@ -681,7 +674,7 @@
681
674
  var HOST_AUTO_INIT_TAG = '__H_A_I__';
682
675
  var hostAutoInitModule = new VirtualModule('hostAutoInit', HOST_AUTO_INIT_TAG);
683
676
  function writeHostAutoInit() {
684
- hostAutoInitModule.writeSync("\n import {init} from \"" + REMOTE_ENTRY_ID + "\"\n init()\n ");
677
+ hostAutoInitModule.writeSync("\n const remoteEntryPromise = import(\"" + REMOTE_ENTRY_ID + "\")\n // __tla only serves as a hack for vite-plugin-top-level-await. \n Promise.resolve(remoteEntryPromise)\n .then(remoteEntry => {\n return Promise.resolve(remoteEntry.__tla)\n .then(remoteEntry.init).catch(remoteEntry.init)\n })\n ");
685
678
  }
686
679
  function getHostAutoInitImportId() {
687
680
  return hostAutoInitModule.getImportId();
@@ -1104,7 +1097,7 @@
1104
1097
  if (_command === 'serve') {
1105
1098
  var _viteConfig$server, _viteConfig$server2;
1106
1099
  var host = typeof ((_viteConfig$server = viteConfig.server) == null ? void 0 : _viteConfig$server.host) === 'string' && viteConfig.server.host !== '0.0.0.0' ? viteConfig.server.host : 'localhost';
1107
- return Promise.resolve("\n const {init} = await import(\"//" + host + ":" + ((_viteConfig$server2 = viteConfig.server) == null ? void 0 : _viteConfig$server2.port) + (viteConfig.base + options.filename) + "\")\n init()\n ");
1100
+ return Promise.resolve("\n const origin = window ? window.origin : \"//" + host + ":" + ((_viteConfig$server2 = viteConfig.server) == null ? void 0 : _viteConfig$server2.port) + "\"\n const remoteEntryPromise = await import(origin + \"" + (viteConfig.base + options.filename) + "\")\n // __tla only serves as a hack for vite-plugin-top-level-await. \n Promise.resolve(remoteEntryPromise)\n .then(remoteEntry => {\n return Promise.resolve(remoteEntry.__tla)\n .then(remoteEntry.init).catch(remoteEntry.init)\n })\n ");
1108
1101
  }
1109
1102
  return Promise.resolve(code);
1110
1103
  }
@@ -1219,7 +1212,7 @@
1219
1212
  writePreBuildLibPath(source);
1220
1213
  addUsedShares(source);
1221
1214
  writeLocalSharedImportMap();
1222
- return this.resolve(loadSharePath);
1215
+ return this.resolve(loadSharePath, importer);
1223
1216
  }
1224
1217
  };
1225
1218
  }));
@@ -1238,7 +1231,7 @@
1238
1231
  try {
1239
1232
  var _this = this;
1240
1233
  var pkgName = VirtualModule.findModule(PREBUILD_TAG, source).name;
1241
- return Promise.resolve(_this.resolve(pkgName).then(function (item) {
1234
+ return Promise.resolve(_this.resolve(pkgName, importer).then(function (item) {
1242
1235
  return item.id;
1243
1236
  })).then(function (result) {
1244
1237
  if (!result.includes(_config.cacheDir)) {
@@ -1248,7 +1241,7 @@
1248
1241
  // Fix localSharedImportMap import id
1249
1242
  var _resolve = _this.resolve;
1250
1243
  return Promise.resolve(savePrebuild.get(pkgName)).then(function (_savePrebuild$get) {
1251
- return Promise.resolve(_resolve.call(_this, _savePrebuild$get));
1244
+ return Promise.resolve(_resolve.call(_this, _savePrebuild$get, importer));
1252
1245
  });
1253
1246
  });
1254
1247
  } catch (e) {
@@ -1258,22 +1251,6 @@
1258
1251
  };
1259
1252
  }));
1260
1253
  }
1261
- }, {
1262
- name: 'watchLocalSharedImportMap',
1263
- apply: 'serve',
1264
- config: function config(_config3) {
1265
- _config3.optimizeDeps = defu.defu(_config3.optimizeDeps, {
1266
- exclude: [getLocalSharedImportMapPath()]
1267
- });
1268
- _config3.server = defu.defu(_config3.server, {
1269
- watch: {
1270
- ignored: []
1271
- }
1272
- });
1273
- var watch = _config3.server.watch;
1274
- watch.ignored = [].concat(watch.ignored);
1275
- watch.ignored.push("!**" + getLocalSharedImportMapPath() + "**");
1276
- }
1277
1254
  }];
1278
1255
  }
1279
1256
 
@@ -1346,6 +1323,11 @@
1346
1323
  find: '@module-federation/runtime',
1347
1324
  replacement: options.implementation
1348
1325
  });
1326
+ _config.build = defu__default["default"](_config.build || {}, {
1327
+ commonjsOptions: {
1328
+ strictRequires: 'auto'
1329
+ }
1330
+ });
1349
1331
  (_config$optimizeDeps = _config.optimizeDeps) == null || (_config$optimizeDeps = _config$optimizeDeps.include) == null || _config$optimizeDeps.push('@module-federation/runtime');
1350
1332
  (_config$optimizeDeps2 = _config.optimizeDeps) == null || (_config$optimizeDeps2 = _config$optimizeDeps2.include) == null || _config$optimizeDeps2.push('__mf__virtual');
1351
1333
  (_config$optimizeDeps3 = _config.optimizeDeps) == null || (_config$optimizeDeps3 = _config$optimizeDeps3.needsInterop) == null || _config$optimizeDeps3.push('__mf__virtual');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/vite",
3
- "version": "1.1.9",
3
+ "version": "1.2.1",
4
4
  "description": "Vite plugin for Module Federation",
5
5
  "type": "module",
6
6
  "source": "src/index.ts",