@module-federation/vite 1.1.8 → 1.1.9

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
@@ -67,8 +67,11 @@ var addEntry = function addEntry(_ref) {
67
67
  configureServer: function configureServer(server) {
68
68
  var _server$httpServer;
69
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) {});
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) {});
72
75
  });
73
76
  server.middlewares.use(function (req, res, next) {
74
77
  if (!fileName) {
@@ -84,6 +87,15 @@ var addEntry = function addEntry(_ref) {
84
87
  transformIndexHtml: function transformIndexHtml(c) {
85
88
  if (!injectHtml()) return;
86
89
  return c.replace('<head>', "<head><script type=\"module\" src=" + JSON.stringify(devEntryPath.replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/\\\\?/g, '/')) + "></script>");
90
+ },
91
+ transform: function transform(code, id) {
92
+ if (id.includes('node_modules') || inject !== 'html' || htmlFilePath) {
93
+ return;
94
+ }
95
+ if (id.includes('.svelte-kit') && id.includes('internal.js')) {
96
+ var src = devEntryPath.replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/\\\\?/g, '/');
97
+ return code.replace(/<head>/g, '<head><script type=\\"module\\" src=\\"' + src + '\\"></script>');
98
+ }
87
99
  }
88
100
  }, {
89
101
  name: 'add-entry',
@@ -1092,8 +1104,9 @@ function pluginProxyRemoteEntry () {
1092
1104
  if (id.includes(getHostAutoInitPath())) {
1093
1105
  var options = getNormalizeModuleFederationOptions();
1094
1106
  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 ");
1107
+ var _viteConfig$server, _viteConfig$server2;
1108
+ 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 ");
1097
1110
  }
1098
1111
  return Promise.resolve(code);
1099
1112
  }
package/lib/index.esm.js CHANGED
@@ -44,8 +44,11 @@ var addEntry = function addEntry(_ref) {
44
44
  configureServer: function configureServer(server) {
45
45
  var _server$httpServer;
46
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) {});
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) {});
49
52
  });
50
53
  server.middlewares.use(function (req, res, next) {
51
54
  if (!fileName) {
@@ -61,6 +64,15 @@ var addEntry = function addEntry(_ref) {
61
64
  transformIndexHtml: function transformIndexHtml(c) {
62
65
  if (!injectHtml()) return;
63
66
  return c.replace('<head>', "<head><script type=\"module\" src=" + JSON.stringify(devEntryPath.replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/\\\\?/g, '/')) + "></script>");
67
+ },
68
+ transform: function transform(code, id) {
69
+ if (id.includes('node_modules') || inject !== 'html' || htmlFilePath) {
70
+ return;
71
+ }
72
+ if (id.includes('.svelte-kit') && id.includes('internal.js')) {
73
+ var src = devEntryPath.replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/\\\\?/g, '/');
74
+ return code.replace(/<head>/g, '<head><script type=\\"module\\" src=\\"' + src + '\\"></script>');
75
+ }
64
76
  }
65
77
  }, {
66
78
  name: 'add-entry',
@@ -1069,8 +1081,9 @@ function pluginProxyRemoteEntry () {
1069
1081
  if (id.includes(getHostAutoInitPath())) {
1070
1082
  var options = getNormalizeModuleFederationOptions();
1071
1083
  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 ");
1084
+ var _viteConfig$server, _viteConfig$server2;
1085
+ 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 ");
1074
1087
  }
1075
1088
  return Promise.resolve(code);
1076
1089
  }
@@ -44,9 +44,11 @@ const addEntry = ({
44
44
  var _server$httpServer;
45
45
  (_server$httpServer = server.httpServer) == null || _server$httpServer.once == null || _server$httpServer.once('listening', () => {
46
46
  const {
47
- port
47
+ port,
48
+ host: hostConfig
48
49
  } = server.config.server;
49
- fetch(`http://localhost:${port}${devEntryPath}`).catch(e => {});
50
+ const host = typeof hostConfig === 'string' && hostConfig !== '0.0.0.0' ? hostConfig : 'localhost';
51
+ fetch(`http://${host}:${port}${devEntryPath}`).catch(e => {});
50
52
  });
51
53
  server.middlewares.use((req, res, next) => {
52
54
  if (!fileName) {
@@ -62,6 +64,15 @@ const addEntry = ({
62
64
  transformIndexHtml(c) {
63
65
  if (!injectHtml()) return;
64
66
  return c.replace('<head>', `<head><script type="module" src=${JSON.stringify(devEntryPath.replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/\\\\?/g, '/'))}></script>`);
67
+ },
68
+ transform(code, id) {
69
+ if (id.includes('node_modules') || _inject !== 'html' || htmlFilePath) {
70
+ return;
71
+ }
72
+ if (id.includes('.svelte-kit') && id.includes('internal.js')) {
73
+ const src = devEntryPath.replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/\\\\?/g, '/');
74
+ return code.replace(/<head>/g, '<head><script type=\\"module\\" src=\\"' + src + '\\"></script>');
75
+ }
65
76
  }
66
77
  }, {
67
78
  name: 'add-entry',
@@ -1136,9 +1147,10 @@ function pluginProxyRemoteEntry () {
1136
1147
  if (id.includes(getHostAutoInitPath())) {
1137
1148
  const options = getNormalizeModuleFederationOptions();
1138
1149
  if (_command === 'serve') {
1139
- var _viteConfig$server;
1150
+ var _viteConfig$server, _viteConfig$server2;
1151
+ 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
1152
  return `
1141
- const {init} = await import("//localhost:${(_viteConfig$server = viteConfig.server) == null ? void 0 : _viteConfig$server.port}${viteConfig.base + options.filename}")
1153
+ const {init} = await import("//${host}:${(_viteConfig$server2 = viteConfig.server) == null ? void 0 : _viteConfig$server2.port}${viteConfig.base + options.filename}")
1142
1154
  init()
1143
1155
  `;
1144
1156
  }
package/lib/index.umd.js CHANGED
@@ -65,8 +65,11 @@
65
65
  configureServer: function configureServer(server) {
66
66
  var _server$httpServer;
67
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) {});
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) {});
70
73
  });
71
74
  server.middlewares.use(function (req, res, next) {
72
75
  if (!fileName) {
@@ -82,6 +85,15 @@
82
85
  transformIndexHtml: function transformIndexHtml(c) {
83
86
  if (!injectHtml()) return;
84
87
  return c.replace('<head>', "<head><script type=\"module\" src=" + JSON.stringify(devEntryPath.replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/\\\\?/g, '/')) + "></script>");
88
+ },
89
+ transform: function transform(code, id) {
90
+ if (id.includes('node_modules') || inject !== 'html' || htmlFilePath) {
91
+ return;
92
+ }
93
+ if (id.includes('.svelte-kit') && id.includes('internal.js')) {
94
+ var src = devEntryPath.replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/\\\\?/g, '/');
95
+ return code.replace(/<head>/g, '<head><script type=\\"module\\" src=\\"' + src + '\\"></script>');
96
+ }
85
97
  }
86
98
  }, {
87
99
  name: 'add-entry',
@@ -1090,8 +1102,9 @@
1090
1102
  if (id.includes(getHostAutoInitPath())) {
1091
1103
  var options = getNormalizeModuleFederationOptions();
1092
1104
  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 ");
1105
+ var _viteConfig$server, _viteConfig$server2;
1106
+ 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 ");
1095
1108
  }
1096
1109
  return Promise.resolve(code);
1097
1110
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/vite",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
4
4
  "description": "Vite plugin for Module Federation",
5
5
  "type": "module",
6
6
  "source": "src/index.ts",