-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/hasanayan/craco-module-fe…
…deration into main
- Loading branch information
Showing
50 changed files
with
31,916 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
const webpack = require("webpack"); | ||
const ModuleFederationPlugin = webpack.container.ModuleFederationPlugin; | ||
const ExternalTemplateRemotesPlugin = require("external-remotes-plugin"); | ||
|
||
module.exports = { | ||
overrideWebpackConfig: ({ | ||
webpackConfig, | ||
context: { env }, | ||
pluginOptions: { | ||
namedModuleIdsOnProduction = false, | ||
namedChunkIdsOnProduction = false, | ||
}, | ||
}) => { | ||
const fastRefreshEnabled = process.env.FAST_REFRESH !== "false"; | ||
const isEnvDevelopment = env === "development"; | ||
|
||
webpackConfig.output = { | ||
...webpackConfig.output, | ||
publicPath: "auto", | ||
}; | ||
|
||
webpackConfig.optimization = { | ||
chunkIds: | ||
isEnvDevelopment || namedChunkIdsOnProduction ? "named" : undefined, | ||
moduleIds: | ||
isEnvDevelopment || namedModuleIdsOnProduction ? "named" : undefined, | ||
}; | ||
|
||
webpackConfig.plugins[1].userOptions.hash = true; | ||
if (fastRefreshEnabled && isEnvDevelopment) { | ||
webpackConfig.plugins[1].userOptions.chunks = ["main"]; | ||
} | ||
|
||
return webpackConfig; | ||
}, | ||
|
||
overrideCracoConfig: ({ | ||
cracoConfig, | ||
pluginOptions: { | ||
federationConfig, | ||
useExternalRemotesPlugin = false, | ||
removeWatchMissingNodeModulesPlugin = true, | ||
}, | ||
}) => { | ||
if (!cracoConfig.webpack) cracoConfig.webpack = {}; | ||
if (!cracoConfig.webpack.plugins) cracoConfig.webpack.plugins = {}; | ||
|
||
cracoConfig.webpack.plugins.add = [ | ||
...(cracoConfig.webpack.plugins.add || []), | ||
new ModuleFederationPlugin(federationConfig), | ||
useExternalRemotesPlugin && new ExternalTemplateRemotesPlugin(), | ||
].filter(Boolean); | ||
|
||
cracoConfig.webpack.plugins.remove = ["WebpackManifestPlugin"]; | ||
|
||
cracoConfig.webpack.plugins.remove = [ | ||
...cracoConfig.webpack.plugins.remove, | ||
removeWatchMissingNodeModulesPlugin && "WatchMissingNodeModulesPlugin", | ||
].filter(Boolean); | ||
|
||
return cracoConfig; | ||
}, | ||
}; |
Oops, something went wrong.