question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add additional webpack configuration to withModuleFederation plugin

See original GitHub issue

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch @nrwl/react@14.1.9 for the project I’m working on.

Here is the diff that solved my problem:

diff --git a/node_modules/@nrwl/react/src/module-federation/models.d.ts b/node_modules/@nrwl/react/src/module-federation/models.d.ts
index d42a01a..a91e14e 100644
--- a/node_modules/@nrwl/react/src/module-federation/models.d.ts
+++ b/node_modules/@nrwl/react/src/module-federation/models.d.ts
@@ -21,4 +21,5 @@ export interface ModuleFederationConfig {
     exposes?: Record<string, string>;
     shared?: SharedFunction;
     additionalShared?: AdditionalSharedConfig;
+    webpackConfig?: any;
 }
diff --git a/node_modules/@nrwl/react/src/module-federation/with-module-federation.js b/node_modules/@nrwl/react/src/module-federation/with-module-federation.js
index c0d371c..4961b43 100644
--- a/node_modules/@nrwl/react/src/module-federation/with-module-federation.js
+++ b/node_modules/@nrwl/react/src/module-federation/with-module-federation.js
@@ -9,6 +9,7 @@ const file_utils_1 = require("nx/src/project-graph/file-utils");
 const package_json_1 = require("./package-json");
 const path_1 = require("path");
 const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
+const webpackMerge = require('webpack-merge');
 function collectDependencies(projectGraph, name, dependencies = {
     workspaceLibraries: new Set(),
     npmPackages: new Set(),
@@ -187,7 +188,7 @@ function withModuleFederation(options) {
                 remotes: mappedRemotes,
                 shared: Object.assign({}, sharedDependencies),
             }), sharedLibraries.getReplacementPlugin());
-            return config;
+            return options.webpackConfig ? webpackMerge.merge(config, options.webpackConfig) : config;
         };
     });
 }

This issue body was partially generated by patch-package.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:3
  • Comments:17 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
sscotthcommented, Jun 1, 2022

@AgentEnder No, it doesn’t work

https://github.com/sscotth/nxdemo/blob/main/apps/shop/webpack.config.js

originalOnListen is not a function
TypeError: originalOnListen is not a function
    at devServerConfig.onListening (.../node_modules/@nrwl/web/src/utils/run-webpack.js:48:13)
    at Server.start (.../webpack-dev-server/lib/Server.js:3245:20)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
4reactions
akhilsreenivasancommented, Jun 1, 2022

webpack-merge won’t handle promise and tried to implement module.exports = async (webpackConfig) => { return (await withModuleFederation(config))({ ...webpackConfig, output: { ...webpackConfig.output, scriptType: 'text/javascript' } }); }; but no luck, because async exports is not working and host server is not getting started

Read more comments on GitHub >

github_iconTop Results From Across the Web

ModuleFederationPlugin - webpack
Create a new runtime chunk with the specified name. webpack.config.js const { ModuleFederationPlugin } = require('webpack').container; module.exports ...
Read more >
Customizing Webpack Config - Nx
For most apps, the default configuration of webpack is sufficient, but sometimes you need to tweak a setting in your webpack config. This...
Read more >
How to Build a Micro Frontend with Webpack's Module ...
Here is a quick intro to the Module Federation Plugin, ... Create two new Webpack config files named webpack.config.ts and ...
Read more >
How to use Webpack Module Federation plugin with create ...
Answering because this question is top for Google searches CRA with Module Federation. Update 25 Jan 2022 - CRA 5 has been released...
Read more >
Micro-frontends: Module Federation with WebPack 5
With Module Federation you can import remote Webpack builds to your ... We have included all the Webpack modules to create a basic...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found