Add additional webpack configuration to withModuleFederation plugin
See original GitHub issueHi! 👋
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:
- Created a year ago
- Reactions:3
- Comments:17 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@AgentEnder No, it doesn’t work
https://github.com/sscotth/nxdemo/blob/main/apps/shop/webpack.config.js
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