@nx/module-federation 20.2.0-beta.2 → 20.2.0-beta.4

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.
Files changed (55) hide show
  1. package/angular.d.ts +2 -0
  2. package/angular.js +5 -0
  3. package/index.d.ts +1 -0
  4. package/index.js +4 -0
  5. package/package.json +12 -11
  6. package/rspack.d.ts +2 -0
  7. package/rspack.js +5 -0
  8. package/src/utils/dependencies.d.ts +6 -0
  9. package/src/utils/dependencies.js +56 -0
  10. package/src/utils/get-remotes-for-host.d.ts +16 -0
  11. package/src/utils/get-remotes-for-host.js +97 -0
  12. package/src/utils/index.d.ts +9 -0
  13. package/src/utils/index.js +12 -0
  14. package/src/utils/models/index.d.ts +47 -0
  15. package/src/utils/models/index.js +2 -0
  16. package/src/utils/package-json.d.ts +8 -0
  17. package/src/utils/package-json.js +12 -0
  18. package/src/utils/parse-static-remotes-config.d.ts +13 -0
  19. package/src/utils/parse-static-remotes-config.js +34 -0
  20. package/src/utils/plugins/runtime-library-control.plugin.d.ts +3 -0
  21. package/src/utils/plugins/runtime-library-control.plugin.js +54 -0
  22. package/src/utils/public-api.d.ts +6 -0
  23. package/src/utils/public-api.js +16 -0
  24. package/src/utils/remotes.d.ts +19 -0
  25. package/src/utils/remotes.js +89 -0
  26. package/src/utils/secondary-entry-points.d.ts +12 -0
  27. package/src/utils/secondary-entry-points.js +125 -0
  28. package/src/utils/share.d.ts +49 -0
  29. package/src/utils/share.js +246 -0
  30. package/src/utils/start-remote-proxies.d.ts +5 -0
  31. package/src/utils/start-remote-proxies.js +38 -0
  32. package/src/utils/start-ssr-remote-proxies.d.ts +5 -0
  33. package/src/utils/start-ssr-remote-proxies.js +52 -0
  34. package/src/utils/typescript.d.ts +4 -0
  35. package/src/utils/typescript.js +53 -0
  36. package/src/with-module-federation/angular/utils.d.ts +15 -0
  37. package/src/with-module-federation/angular/utils.js +101 -0
  38. package/src/with-module-federation/angular/with-module-federation-ssr.d.ts +2 -0
  39. package/src/with-module-federation/angular/with-module-federation-ssr.js +77 -0
  40. package/src/with-module-federation/angular/with-module-federation.d.ts +2 -0
  41. package/src/with-module-federation/angular/with-module-federation.js +70 -0
  42. package/src/with-module-federation/rspack/utils.d.ts +12 -0
  43. package/src/with-module-federation/rspack/utils.js +74 -0
  44. package/src/with-module-federation/rspack/with-module-federation-ssr.d.ts +4 -0
  45. package/src/with-module-federation/rspack/with-module-federation-ssr.js +67 -0
  46. package/src/with-module-federation/rspack/with-module-federation.d.ts +9 -0
  47. package/src/with-module-federation/rspack/with-module-federation.js +70 -0
  48. package/src/with-module-federation/webpack/utils.d.ts +12 -0
  49. package/src/with-module-federation/webpack/utils.js +75 -0
  50. package/src/with-module-federation/webpack/with-module-federation-ssr.d.ts +2 -0
  51. package/src/with-module-federation/webpack/with-module-federation-ssr.js +59 -0
  52. package/src/with-module-federation/webpack/with-module-federation.d.ts +5 -0
  53. package/src/with-module-federation/webpack/with-module-federation.js +62 -0
  54. package/webpack.d.ts +2 -0
  55. package/webpack.js +5 -0
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.withModuleFederation = withModuleFederation;
4
+ const utils_1 = require("./utils");
5
+ const webpack_1 = require("@module-federation/enhanced/webpack");
6
+ /**
7
+ * @param {ModuleFederationConfig} options
8
+ */
9
+ async function withModuleFederation(options, configOverride) {
10
+ if (global.NX_GRAPH_CREATION) {
11
+ return (config) => config;
12
+ }
13
+ const { sharedDependencies, sharedLibraries, mappedRemotes } = await (0, utils_1.getModuleFederationConfig)(options);
14
+ return (config, ctx) => {
15
+ config.output.uniqueName = options.name;
16
+ config.output.publicPath = 'auto';
17
+ config.output.scriptType = 'text/javascript';
18
+ config.optimization = {
19
+ ...(config.optimization ?? {}),
20
+ runtimeChunk: false,
21
+ };
22
+ if (config.mode === 'development' &&
23
+ Object.keys(mappedRemotes).length > 1 &&
24
+ !options.exposes) {
25
+ config.optimization.runtimeChunk = 'single';
26
+ }
27
+ config.plugins.push(new webpack_1.ModuleFederationPlugin({
28
+ name: options.name.replace(/-/g, '_'),
29
+ filename: 'remoteEntry.js',
30
+ exposes: options.exposes,
31
+ remotes: mappedRemotes,
32
+ shared: {
33
+ ...sharedDependencies,
34
+ },
35
+ /**
36
+ * remoteType: 'script' is required for the remote to be loaded as a script tag.
37
+ * remotes will need to be defined as:
38
+ * { appX: 'appX@http://localhost:3001/remoteEntry.js' }
39
+ * { appY: 'appY@http://localhost:3002/remoteEntry.js' }
40
+ */
41
+ remoteType: 'script',
42
+ /**
43
+ * Apply user-defined config overrides
44
+ */
45
+ ...(configOverride ? configOverride : {}),
46
+ runtimePlugins: process.env.NX_MF_DEV_REMOTES &&
47
+ !options.disableNxRuntimeLibraryControlPlugin
48
+ ? [
49
+ ...(configOverride?.runtimePlugins ?? []),
50
+ require.resolve('@nx/module-federation/src/utils/plugins/runtime-library-control.plugin.js'),
51
+ ]
52
+ : configOverride?.runtimePlugins,
53
+ virtualRuntimeEntry: true,
54
+ }), sharedLibraries.getReplacementPlugin());
55
+ // The env var is only set from the module-federation-dev-server
56
+ // Attach the runtime plugin
57
+ config.plugins.push(new (require('webpack').DefinePlugin)({
58
+ 'process.env.NX_MF_DEV_REMOTES': process.env.NX_MF_DEV_REMOTES,
59
+ }));
60
+ return config;
61
+ };
62
+ }
package/webpack.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './src/with-module-federation/webpack/with-module-federation';
2
+ export * from './src/with-module-federation/webpack/with-module-federation-ssr';
package/webpack.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./src/with-module-federation/webpack/with-module-federation"), exports);
5
+ tslib_1.__exportStar(require("./src/with-module-federation/webpack/with-module-federation-ssr"), exports);