@module-federation/vite 1.1.8 → 1.2.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/README.md CHANGED
@@ -17,6 +17,8 @@ This plugin makes Module Federation work together with [Vite](https://vitejs.dev
17
17
 
18
18
  ### [Svelte](https://github.com/gioboa/svelte-microfrontend-demo)<br>
19
19
 
20
+ ### [SvelteKit](https://github.com/gioboa/sveltekit-microfrontend-demo)<br>
21
+
20
22
  ### [SolidJS](https://github.com/gioboa/solid-microfrontend-demo)<br>
21
23
 
22
24
  ### [More examples here](https://github.com/module-federation/vite/tree/main/examples)<br>
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,11 +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 port = server.config.server.port;
71
- fetch("http://localhost:" + port + devEntryPath)["catch"](function (e) {});
72
- });
73
69
  server.middlewares.use(function (req, res, next) {
74
70
  if (!fileName) {
75
71
  next();
@@ -84,6 +80,15 @@ var addEntry = function addEntry(_ref) {
84
80
  transformIndexHtml: function transformIndexHtml(c) {
85
81
  if (!injectHtml()) return;
86
82
  return c.replace('<head>', "<head><script type=\"module\" src=" + JSON.stringify(devEntryPath.replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/\\\\?/g, '/')) + "></script>");
83
+ },
84
+ transform: function transform(code, id) {
85
+ if (id.includes('node_modules') || inject !== 'html' || htmlFilePath) {
86
+ return;
87
+ }
88
+ if (id.includes('.svelte-kit') && id.includes('internal.js')) {
89
+ var src = devEntryPath.replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/\\\\?/g, '/');
90
+ return code.replace(/<head>/g, '<head><script type=\\"module\\" src=\\"' + src + '\\"></script>');
91
+ }
87
92
  }
88
93
  }, {
89
94
  name: 'add-entry',
@@ -671,7 +676,7 @@ function generateRemoteEntry(options) {
671
676
  var HOST_AUTO_INIT_TAG = '__H_A_I__';
672
677
  var hostAutoInitModule = new VirtualModule('hostAutoInit', HOST_AUTO_INIT_TAG);
673
678
  function writeHostAutoInit() {
674
- 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 ");
675
680
  }
676
681
  function getHostAutoInitImportId() {
677
682
  return hostAutoInitModule.getImportId();
@@ -1092,8 +1097,9 @@ function pluginProxyRemoteEntry () {
1092
1097
  if (id.includes(getHostAutoInitPath())) {
1093
1098
  var options = getNormalizeModuleFederationOptions();
1094
1099
  if (_command === 'serve') {
1095
- var _viteConfig$server;
1096
- return Promise.resolve("\n const {init} = await import(\"//localhost:" + ((_viteConfig$server = viteConfig.server) == null ? void 0 : _viteConfig$server.port) + (viteConfig.base + options.filename) + "\")\n init()\n ");
1100
+ var _viteConfig$server, _viteConfig$server2;
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';
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 ");
1097
1103
  }
1098
1104
  return Promise.resolve(code);
1099
1105
  }
@@ -1247,22 +1253,6 @@ function proxySharedModule(options) {
1247
1253
  };
1248
1254
  }));
1249
1255
  }
1250
- }, {
1251
- name: 'watchLocalSharedImportMap',
1252
- apply: 'serve',
1253
- config: function config(_config3) {
1254
- _config3.optimizeDeps = defu.defu(_config3.optimizeDeps, {
1255
- exclude: [getLocalSharedImportMapPath()]
1256
- });
1257
- _config3.server = defu.defu(_config3.server, {
1258
- watch: {
1259
- ignored: []
1260
- }
1261
- });
1262
- var watch = _config3.server.watch;
1263
- watch.ignored = [].concat(watch.ignored);
1264
- watch.ignored.push("!**" + getLocalSharedImportMapPath() + "**");
1265
- }
1266
1256
  }];
1267
1257
  }
1268
1258
 
@@ -1335,6 +1325,11 @@ function federation(mfUserOptions) {
1335
1325
  find: '@module-federation/runtime',
1336
1326
  replacement: options.implementation
1337
1327
  });
1328
+ _config.build = defu__default["default"](_config.build || {}, {
1329
+ commonjsOptions: {
1330
+ strictRequires: 'auto'
1331
+ }
1332
+ });
1338
1333
  (_config$optimizeDeps = _config.optimizeDeps) == null || (_config$optimizeDeps = _config$optimizeDeps.include) == null || _config$optimizeDeps.push('@module-federation/runtime');
1339
1334
  (_config$optimizeDeps2 = _config.optimizeDeps) == null || (_config$optimizeDeps2 = _config$optimizeDeps2.include) == null || _config$optimizeDeps2.push('__mf__virtual');
1340
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,11 +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 port = server.config.server.port;
48
- fetch("http://localhost:" + port + devEntryPath)["catch"](function (e) {});
49
- });
50
45
  server.middlewares.use(function (req, res, next) {
51
46
  if (!fileName) {
52
47
  next();
@@ -61,6 +56,15 @@ var addEntry = function addEntry(_ref) {
61
56
  transformIndexHtml: function transformIndexHtml(c) {
62
57
  if (!injectHtml()) return;
63
58
  return c.replace('<head>', "<head><script type=\"module\" src=" + JSON.stringify(devEntryPath.replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/\\\\?/g, '/')) + "></script>");
59
+ },
60
+ transform: function transform(code, id) {
61
+ if (id.includes('node_modules') || inject !== 'html' || htmlFilePath) {
62
+ return;
63
+ }
64
+ if (id.includes('.svelte-kit') && id.includes('internal.js')) {
65
+ var src = devEntryPath.replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/\\\\?/g, '/');
66
+ return code.replace(/<head>/g, '<head><script type=\\"module\\" src=\\"' + src + '\\"></script>');
67
+ }
64
68
  }
65
69
  }, {
66
70
  name: 'add-entry',
@@ -648,7 +652,7 @@ function generateRemoteEntry(options) {
648
652
  var HOST_AUTO_INIT_TAG = '__H_A_I__';
649
653
  var hostAutoInitModule = new VirtualModule('hostAutoInit', HOST_AUTO_INIT_TAG);
650
654
  function writeHostAutoInit() {
651
- 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 ");
652
656
  }
653
657
  function getHostAutoInitImportId() {
654
658
  return hostAutoInitModule.getImportId();
@@ -1069,8 +1073,9 @@ function pluginProxyRemoteEntry () {
1069
1073
  if (id.includes(getHostAutoInitPath())) {
1070
1074
  var options = getNormalizeModuleFederationOptions();
1071
1075
  if (_command === 'serve') {
1072
- var _viteConfig$server;
1073
- return Promise.resolve("\n const {init} = await import(\"//localhost:" + ((_viteConfig$server = viteConfig.server) == null ? void 0 : _viteConfig$server.port) + (viteConfig.base + options.filename) + "\")\n init()\n ");
1076
+ var _viteConfig$server, _viteConfig$server2;
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';
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 ");
1074
1079
  }
1075
1080
  return Promise.resolve(code);
1076
1081
  }
@@ -1224,22 +1229,6 @@ function proxySharedModule(options) {
1224
1229
  };
1225
1230
  }));
1226
1231
  }
1227
- }, {
1228
- name: 'watchLocalSharedImportMap',
1229
- apply: 'serve',
1230
- config: function config(_config3) {
1231
- _config3.optimizeDeps = defu(_config3.optimizeDeps, {
1232
- exclude: [getLocalSharedImportMapPath()]
1233
- });
1234
- _config3.server = defu(_config3.server, {
1235
- watch: {
1236
- ignored: []
1237
- }
1238
- });
1239
- var watch = _config3.server.watch;
1240
- watch.ignored = [].concat(watch.ignored);
1241
- watch.ignored.push("!**" + getLocalSharedImportMapPath() + "**");
1242
- }
1243
1232
  }];
1244
1233
  }
1245
1234
 
@@ -1312,6 +1301,11 @@ function federation(mfUserOptions) {
1312
1301
  find: '@module-federation/runtime',
1313
1302
  replacement: options.implementation
1314
1303
  });
1304
+ _config.build = defu(_config.build || {}, {
1305
+ commonjsOptions: {
1306
+ strictRequires: 'auto'
1307
+ }
1308
+ });
1315
1309
  (_config$optimizeDeps = _config.optimizeDeps) == null || (_config$optimizeDeps = _config$optimizeDeps.include) == null || _config$optimizeDeps.push('@module-federation/runtime');
1316
1310
  (_config$optimizeDeps2 = _config.optimizeDeps) == null || (_config$optimizeDeps2 = _config$optimizeDeps2.include) == null || _config$optimizeDeps2.push('__mf__virtual');
1317
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,13 +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
- } = server.config.server;
49
- fetch(`http://localhost:${port}${devEntryPath}`).catch(e => {});
50
- });
51
44
  server.middlewares.use((req, res, next) => {
52
45
  if (!fileName) {
53
46
  next();
@@ -62,6 +55,15 @@ const addEntry = ({
62
55
  transformIndexHtml(c) {
63
56
  if (!injectHtml()) return;
64
57
  return c.replace('<head>', `<head><script type="module" src=${JSON.stringify(devEntryPath.replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/\\\\?/g, '/'))}></script>`);
58
+ },
59
+ transform(code, id) {
60
+ if (id.includes('node_modules') || _inject !== 'html' || htmlFilePath) {
61
+ return;
62
+ }
63
+ if (id.includes('.svelte-kit') && id.includes('internal.js')) {
64
+ const src = devEntryPath.replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/\\\\?/g, '/');
65
+ return code.replace(/<head>/g, '<head><script type=\\"module\\" src=\\"' + src + '\\"></script>');
66
+ }
65
67
  }
66
68
  }, {
67
69
  name: 'add-entry',
@@ -742,8 +744,13 @@ const HOST_AUTO_INIT_TAG = '__H_A_I__';
742
744
  const hostAutoInitModule = new VirtualModule('hostAutoInit', HOST_AUTO_INIT_TAG);
743
745
  function writeHostAutoInit() {
744
746
  hostAutoInitModule.writeSync(`
745
- import {init} from "${REMOTE_ENTRY_ID}"
746
- 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
+ })
747
754
  `);
748
755
  }
749
756
  function getHostAutoInitImportId() {
@@ -1136,10 +1143,17 @@ function pluginProxyRemoteEntry () {
1136
1143
  if (id.includes(getHostAutoInitPath())) {
1137
1144
  const options = getNormalizeModuleFederationOptions();
1138
1145
  if (_command === 'serve') {
1139
- var _viteConfig$server;
1146
+ var _viteConfig$server, _viteConfig$server2;
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';
1140
1148
  return `
1141
- const {init} = await import("//localhost:${(_viteConfig$server = viteConfig.server) == null ? void 0 : _viteConfig$server.port}${viteConfig.base + options.filename}")
1142
- 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
+ })
1143
1157
  `;
1144
1158
  }
1145
1159
  return code;
@@ -1278,22 +1292,6 @@ function proxySharedModule(options) {
1278
1292
  };
1279
1293
  }));
1280
1294
  }
1281
- }, {
1282
- name: 'watchLocalSharedImportMap',
1283
- apply: 'serve',
1284
- config(config) {
1285
- config.optimizeDeps = defu(config.optimizeDeps, {
1286
- exclude: [getLocalSharedImportMapPath()]
1287
- });
1288
- config.server = defu(config.server, {
1289
- watch: {
1290
- ignored: []
1291
- }
1292
- });
1293
- const watch = config.server.watch;
1294
- watch.ignored = [].concat(watch.ignored);
1295
- watch.ignored.push(`!**${getLocalSharedImportMapPath()}**`);
1296
- }
1297
1295
  }];
1298
1296
  }
1299
1297
 
@@ -1375,6 +1373,11 @@ function federation(mfUserOptions) {
1375
1373
  find: '@module-federation/runtime',
1376
1374
  replacement: options.implementation
1377
1375
  });
1376
+ config.build = defu(config.build || {}, {
1377
+ commonjsOptions: {
1378
+ strictRequires: 'auto'
1379
+ }
1380
+ });
1378
1381
  (_config$optimizeDeps = config.optimizeDeps) == null || (_config$optimizeDeps = _config$optimizeDeps.include) == null || _config$optimizeDeps.push('@module-federation/runtime');
1379
1382
  (_config$optimizeDeps2 = config.optimizeDeps) == null || (_config$optimizeDeps2 = _config$optimizeDeps2.include) == null || _config$optimizeDeps2.push('__mf__virtual');
1380
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,11 +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 port = server.config.server.port;
69
- fetch("http://localhost:" + port + devEntryPath)["catch"](function (e) {});
70
- });
71
67
  server.middlewares.use(function (req, res, next) {
72
68
  if (!fileName) {
73
69
  next();
@@ -82,6 +78,15 @@
82
78
  transformIndexHtml: function transformIndexHtml(c) {
83
79
  if (!injectHtml()) return;
84
80
  return c.replace('<head>', "<head><script type=\"module\" src=" + JSON.stringify(devEntryPath.replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/\\\\?/g, '/')) + "></script>");
81
+ },
82
+ transform: function transform(code, id) {
83
+ if (id.includes('node_modules') || inject !== 'html' || htmlFilePath) {
84
+ return;
85
+ }
86
+ if (id.includes('.svelte-kit') && id.includes('internal.js')) {
87
+ var src = devEntryPath.replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/\\\\?/g, '/');
88
+ return code.replace(/<head>/g, '<head><script type=\\"module\\" src=\\"' + src + '\\"></script>');
89
+ }
85
90
  }
86
91
  }, {
87
92
  name: 'add-entry',
@@ -669,7 +674,7 @@
669
674
  var HOST_AUTO_INIT_TAG = '__H_A_I__';
670
675
  var hostAutoInitModule = new VirtualModule('hostAutoInit', HOST_AUTO_INIT_TAG);
671
676
  function writeHostAutoInit() {
672
- 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 ");
673
678
  }
674
679
  function getHostAutoInitImportId() {
675
680
  return hostAutoInitModule.getImportId();
@@ -1090,8 +1095,9 @@
1090
1095
  if (id.includes(getHostAutoInitPath())) {
1091
1096
  var options = getNormalizeModuleFederationOptions();
1092
1097
  if (_command === 'serve') {
1093
- var _viteConfig$server;
1094
- return Promise.resolve("\n const {init} = await import(\"//localhost:" + ((_viteConfig$server = viteConfig.server) == null ? void 0 : _viteConfig$server.port) + (viteConfig.base + options.filename) + "\")\n init()\n ");
1098
+ var _viteConfig$server, _viteConfig$server2;
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';
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 ");
1095
1101
  }
1096
1102
  return Promise.resolve(code);
1097
1103
  }
@@ -1245,22 +1251,6 @@
1245
1251
  };
1246
1252
  }));
1247
1253
  }
1248
- }, {
1249
- name: 'watchLocalSharedImportMap',
1250
- apply: 'serve',
1251
- config: function config(_config3) {
1252
- _config3.optimizeDeps = defu.defu(_config3.optimizeDeps, {
1253
- exclude: [getLocalSharedImportMapPath()]
1254
- });
1255
- _config3.server = defu.defu(_config3.server, {
1256
- watch: {
1257
- ignored: []
1258
- }
1259
- });
1260
- var watch = _config3.server.watch;
1261
- watch.ignored = [].concat(watch.ignored);
1262
- watch.ignored.push("!**" + getLocalSharedImportMapPath() + "**");
1263
- }
1264
1254
  }];
1265
1255
  }
1266
1256
 
@@ -1333,6 +1323,11 @@
1333
1323
  find: '@module-federation/runtime',
1334
1324
  replacement: options.implementation
1335
1325
  });
1326
+ _config.build = defu__default["default"](_config.build || {}, {
1327
+ commonjsOptions: {
1328
+ strictRequires: 'auto'
1329
+ }
1330
+ });
1336
1331
  (_config$optimizeDeps = _config.optimizeDeps) == null || (_config$optimizeDeps = _config$optimizeDeps.include) == null || _config$optimizeDeps.push('@module-federation/runtime');
1337
1332
  (_config$optimizeDeps2 = _config.optimizeDeps) == null || (_config$optimizeDeps2 = _config$optimizeDeps2.include) == null || _config$optimizeDeps2.push('__mf__virtual');
1338
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.8",
3
+ "version": "1.2.0",
4
4
  "description": "Vite plugin for Module Federation",
5
5
  "type": "module",
6
6
  "source": "src/index.ts",
@@ -9,22 +9,6 @@
9
9
  "files": [
10
10
  "lib/**/*"
11
11
  ],
12
- "scripts": {
13
- "prepare": "husky install",
14
- "fmt": "prettier --write src",
15
- "fmt.check": "prettier --check src",
16
- "format": "pretty-quick",
17
- "dev": "microbundle watch --no-sourcemap --compress=false",
18
- "build": "rimraf lib && microbundle --no-sourcemap --compress=false",
19
- "dev-rv": "pnpm -filter 'examples-rust-vite*' run dev",
20
- "preview-rv": "pnpm -filter 'examples-rust-vite*' run preview",
21
- "dev-vv": "pnpm -filter 'examples-vite-vite*' run dev",
22
- "dev-nv": "pnpm -filter 'examples-nuxt-vite-host' -filter 'examples-vite-vite-remote' run dev",
23
- "preview-vv": "pnpm -filter 'examples-vite-vite*' run preview",
24
- "multi-example": "pnpm --filter \"multi-example-*\" --parallel run start",
25
- "test": "vitest",
26
- "e2e": "playwright test"
27
- },
28
12
  "repository": {
29
13
  "type": "git",
30
14
  "url": "git+https://github.com/module-federation/vite.git"
@@ -44,7 +28,6 @@
44
28
  "url": "https://github.com/module-federation/vite/issues"
45
29
  },
46
30
  "homepage": "https://github.com/module-federation/vite#readme",
47
- "packageManager": "pnpm@9.1.3",
48
31
  "dependencies": {
49
32
  "@module-federation/runtime": "^0.8.0",
50
33
  "@rollup/pluginutils": "^5.1.0",
@@ -65,5 +48,20 @@
65
48
  "vite": "^5.4.3",
66
49
  "vitest": "^2.1.1",
67
50
  "wait-on": "^8.0.1"
51
+ },
52
+ "scripts": {
53
+ "fmt": "prettier --write src",
54
+ "fmt.check": "prettier --check src",
55
+ "format": "pretty-quick",
56
+ "dev": "microbundle watch --no-sourcemap --compress=false",
57
+ "build": "rimraf lib && microbundle --no-sourcemap --compress=false",
58
+ "dev-rv": "pnpm -filter 'examples-rust-vite*' run dev",
59
+ "preview-rv": "pnpm -filter 'examples-rust-vite*' run preview",
60
+ "dev-vv": "pnpm -filter 'examples-vite-vite*' run dev",
61
+ "dev-nv": "pnpm -filter 'examples-nuxt-vite-host' -filter 'examples-vite-vite-remote' run dev",
62
+ "preview-vv": "pnpm -filter 'examples-vite-vite*' run preview",
63
+ "multi-example": "pnpm --filter \"multi-example-*\" --parallel run start",
64
+ "test": "vitest",
65
+ "e2e": "playwright test"
68
66
  }
69
- }
67
+ }