@module-federation/nextjs-mf 5.1.2 → 5.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/README.md CHANGED
@@ -5,7 +5,7 @@ This plugin enables Module Federation on Next.js
5
5
  ### Supports
6
6
 
7
7
  - next ^11.x.x || ^12.x.x
8
- - Client side only, SSR is another package currently in beta
8
+ - Client side only, SSR has a PR open. Help needed
9
9
 
10
10
  I highly recommend referencing this application which takes advantage of the best capabilities:
11
11
  https://github.com/module-federation/module-federation-examples
@@ -16,6 +16,8 @@ SSR support for federated applications is much harder, as such - it utilizes a d
16
16
  If you need SSR support, consider this package instead - it does everything that nextjs-mf does, and them some.
17
17
  https://app.privjs.com/buy/packageDetail?pkg=@module-federation/nextjs-ssr
18
18
 
19
+ There is a pull request moving SSR into this repo and package - but it is not ready yet.
20
+
19
21
  ## Whats shared by default?
20
22
 
21
23
  Under the hood we share some next internals automatically
@@ -132,6 +134,7 @@ new NextFederationPlugin({
132
134
  exposePages: true, // `false` by default
133
135
  enableImageLoaderFix: true, // `false` by default
134
136
  enableUrlLoaderFix: true, // `false` by default
137
+ skipSharingNextInternals: true // `false` by default
135
138
  },
136
139
  });
137
140
  ```
@@ -139,6 +142,7 @@ new NextFederationPlugin({
139
142
  - `exposePages` – exposes automatically all nextjs pages for you and theirs `./pages-map`.
140
143
  - `enableImageLoaderFix` – adds public hostname to all assets bundled by `nextjs-image-loader`. So if you serve remoteEntry from `http://example.com` then all bundled assets will get this hostname in runtime. It's something like Base URL in HTML but for federated modules.
141
144
  - `enableUrlLoaderFix` – adds public hostname to all assets bundled by `url-loader`.
145
+ - `skipSharingNextInternals` - skips sharing of common nextjs modules. Helpful when you would like explicit control over shared modules, such as a non-nextjs host with a federated nextjs child application.
142
146
 
143
147
  ## Demo
144
148
 
@@ -220,13 +220,15 @@ class ChildFederation {
220
220
  },
221
221
  runtime: false,
222
222
  shared: {
223
- ...externalizedShares,
223
+ ...(this._extraOptions.skipSharingNextInternals
224
+ ? {}
225
+ : externalizedShares),
224
226
  ...this._options.shared,
225
227
  },
226
228
  }),
227
229
  new webpack.web.JsonpTemplatePlugin(childOutput),
228
230
  new LoaderTargetPlugin('web'),
229
- new LibraryPlugin('var'),
231
+ new LibraryPlugin(this._options.library.type),
230
232
  new webpack.DefinePlugin({
231
233
  'process.env.REMOTES': JSON.stringify(this._options.remotes),
232
234
  'process.env.CURRENT_HOST': JSON.stringify(this._options.name),
@@ -428,6 +430,14 @@ class NextFederationPlugin {
428
430
  );
429
431
  this._options.remotes = parsedRemotes;
430
432
  }
433
+ if(this._options.library) {
434
+ console.error('[mf] you cannot set custom library');
435
+ }
436
+ this._options.library = {
437
+ // assign remote name to object to avoid SWC mangling top level variable
438
+ type: 'window',
439
+ name: this._options.name,
440
+ };
431
441
  }
432
442
 
433
443
  apply(compiler) {
@@ -23,8 +23,9 @@ module.exports.hasLoader = function hasLoader(rule, loaderName) {
23
23
  const loader = rule.use[i];
24
24
  // check exact name, eg "url-loader" or its path "node_modules/url-loader/dist/cjs.js"
25
25
  if (
26
- loader.loader === loaderName ||
27
- loader.loader.includes(`/${loaderName}/`)
26
+ loader.loader &&
27
+ (loader.loader === loaderName ||
28
+ loader.loader.includes(`/${loaderName}/`))
28
29
  ) {
29
30
  return true;
30
31
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "public": true,
3
3
  "name": "@module-federation/nextjs-mf",
4
- "version": "5.1.2",
4
+ "version": "5.2.1",
5
5
  "description": "Module Federation helper for NextJS",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/index.d.ts",
@@ -11,7 +11,8 @@
11
11
  "scripts": {
12
12
  "demo": "yarn build && cd demo && yarn install && yarn dev",
13
13
  "prettier": "prettier --write \"**/*.{js,json,md,ts,tsx}\"",
14
- "build": "rm -rf lib && cp -r ./src/ lib/ && rollup -c"
14
+ "build": "rm -rf lib && cp -r ./src/ lib/ && rollup -c",
15
+ "prepublishOnly": "yarn build"
15
16
  },
16
17
  "dependencies": {
17
18
  "chalk": "^4.0.0",