Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docusaurus/website/sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"can-i-use-decorators",
"pre-rendering-into-static-html-files",
"advanced-configuration",
"module-federation",
"alternatives-to-ejecting"
],
"Support": ["troubleshooting"]
Expand Down
18 changes: 18 additions & 0 deletions packages/react-scripts/config/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ const moduleFileExtensions = [
'jsx',
];

const moduleFederationConfigFiles = [
'.modulefederationrc.json',
'.modulefederationrc.js',
];

// Resolve file paths in the same order as webpack
const resolveModule = (resolveFn, filePath) => {
const extension = moduleFileExtensions.find(extension =>
Expand Down Expand Up @@ -73,6 +78,10 @@ module.exports = {
yarnLockFile: resolveApp('yarn.lock'),
testsSetup: resolveModule(resolveApp, 'src/setupTests'),
proxySetup: resolveApp('src/setupProxy.js'),
appMFConfigFile: moduleFederationConfigFiles
.map(resolveApp)
.filter(fs.existsSync)
.shift(),
appNodeModules: resolveApp('node_modules'),
appWebpackCache: resolveApp('node_modules/.cache'),
appTsBuildInfoFile: resolveApp('node_modules/.cache/tsconfig.tsbuildinfo'),
Expand All @@ -98,6 +107,10 @@ module.exports = {
yarnLockFile: resolveApp('yarn.lock'),
testsSetup: resolveModule(resolveApp, 'src/setupTests'),
proxySetup: resolveApp('src/setupProxy.js'),
appMFConfigFile: moduleFederationConfigFiles
.map(resolveApp)
.filter(fs.existsSync)
.shift(),
appNodeModules: resolveApp('node_modules'),
appWebpackCache: resolveApp('node_modules/.cache'),
appTsBuildInfoFile: resolveApp('node_modules/.cache/tsconfig.tsbuildinfo'),
Expand Down Expand Up @@ -136,6 +149,11 @@ if (
yarnLockFile: resolveOwn(`${templatePath}/yarn.lock`),
testsSetup: resolveModule(resolveOwn, `${templatePath}/src/setupTests`),
proxySetup: resolveOwn(`${templatePath}/src/setupProxy.js`),
appMFConfigFile: moduleFederationConfigFiles
.map(p => `${templatePath}/${p}`)
.map(resolveOwn)
.filter(fs.existsSync)
.shift(),
appNodeModules: resolveOwn('node_modules'),
appWebpackCache: resolveOwn('node_modules/.cache'),
appTsBuildInfoFile: resolveOwn('node_modules/.cache/tsconfig.tsbuildinfo'),
Expand Down
17 changes: 16 additions & 1 deletion packages/react-scripts/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ module.exports = function (webpackEnv) {
// webpack uses `publicPath` to determine where the app is being served from.
// It requires a trailing slash, or the file assets will get an incorrect path.
// We inferred the "public path" (such as / or /my-project) from homepage.
publicPath: paths.publicUrlOrPath,
publicPath: 'auto',
// Point sourcemap entries to original disk location (format as URL on Windows)
devtoolModuleFilenameTemplate: isEnvProduction
? info =>
Expand Down Expand Up @@ -353,6 +353,11 @@ module.exports = function (webpackEnv) {
],
},
module: {
generator: {
'asset/resource': {
publicPath: paths.publicUrlOrPath,
},
},
strictExportPresence: true,
rules: [
// Handle node_modules packages that contain sourcemaps
Expand Down Expand Up @@ -617,7 +622,13 @@ module.exports = function (webpackEnv) {
{
inject: true,
template: paths.appHtml,
publicPath: paths.publicUrlOrPath,
},
paths.appMFConfigFile
? {
excludeChunks: [require(paths.appMFConfigFile).name],
}
: undefined,
isEnvProduction
? {
minify: {
Expand Down Expand Up @@ -804,6 +815,10 @@ module.exports = function (webpackEnv) {
},
},
}),
paths.appMFConfigFile &&
new webpack.container.ModuleFederationPlugin(
require(paths.appMFConfigFile)
),
].filter(Boolean),
// Turn off performance processing because we utilize
// our own hints via the FileSizeReporter
Expand Down