Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add module federation support #11241

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
aaddb29
[WP5] Webpack5 update (#10961)
raix May 28, 2021
da654e6
Update Webpack dependencies and fix minor issues (#11170)
Jul 12, 2021
6d3dbed
Merge branch 'main' into wp5
Jul 15, 2021
0a7b095
Merge branch 'main' into wp5
Jul 15, 2021
44c6958
Remove package-lock file
Jul 15, 2021
faf8b66
Drop node 10 and 12, add 16
Jul 15, 2021
b213cf3
Remove dependency check for babel-eslint
Jul 15, 2021
b5caccf
Use md5 for the environment config webpack 5 cache invalidation hash
Jul 15, 2021
f8e0fdb
compile lockfile
Jul 16, 2021
b41322a
Bump @babel/eslint-parser to 7.14.7
Jul 16, 2021
0508303
Fix missing @babel/eslint-parser dev dependency
Jul 16, 2021
18045c0
ModuleScopePlugin ignore @babel/runtime/helpers/esm/assertThisInitial…
Jul 16, 2021
af889e1
Move azurepipelines to ubuntu-latest
Jul 16, 2021
2d3639c
Webpack config remove requireEnsure
Jul 16, 2021
a7b4b6e
ModuleScopePlugin ignore @babel/runtime/regenerator
Jul 16, 2021
c3abea1
Update node-sass from v4 to v6 in fixtures
Jul 16, 2021
7130cdf
Update eslint to 7.30.0
Jul 16, 2021
6e10091
Fix eslint shareable config using rushstack/eslint-patch
Jul 17, 2021
a2df30e
Format eslint patch using prettier
Jul 17, 2021
0674cd7
Remove rest of `TSC_COMPILE_ON_ERROR`
Jul 17, 2021
09cb3d2
Fix html-webpack-plugin asset module support output
Jul 17, 2021
5bf34cd
Revert "Remove rest of `TSC_COMPILE_ON_ERROR`"
Jul 17, 2021
8cf9f02
Add ForkTsCheckerWarningWebpackPlugin to support TSC_COMPILE_ON_ERROR
Jul 17, 2021
892844e
Update css-loader, mini-css-extract-plugin, webpack-dev-server
Jul 20, 2021
a717786
Convert compileType to module in missing css-loaders
Jul 20, 2021
a7de03d
added module federation support
hasanayan Jul 23, 2021
e298678
Update packages/react-scripts/config/paths.js
hasanayan Jul 24, 2021
33dc166
Unify module federation config file name as modulefederation.config.js
hasanayan Jul 24, 2021
0998f9a
Merge remote-tracking branch 'origin' into module-federation
hasanayan Aug 19, 2021
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
23 changes: 19 additions & 4 deletions packages/create-react-app/yarn.lock.cached
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,20 @@
resolved "https://registry.yarnpkg.com/@humanwhocodes/object-schema/-/object-schema-1.2.0.tgz#87de7af9c231826fdd68ac7258f77c429e0e5fcf"
integrity sha512-wdppn25U8z/2yiaT6YGquE6X8sSv7hNMWSXYSSU1jGv/yd6XqjXgTDJ8KP4NgjTXfJ3GbRjeeb8RTV7a/VpM+w==

"@humanwhocodes/config-array@^0.5.0":
version "0.5.0"
resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.5.0.tgz#1407967d4c6eecd7388f83acf1eaf4d0c6e58ef9"
integrity sha512-FagtKFz74XrTl7y6HCzQpwDfXP0yhxe9lHLD1UZxjvZIcbyRz8zTFF/yYNfSfzU414eDwZ1SrO0Qvtyf+wFMQg==
dependencies:
"@humanwhocodes/object-schema" "^1.2.0"
debug "^4.1.1"
minimatch "^3.0.4"

"@humanwhocodes/object-schema@^1.2.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@humanwhocodes/object-schema/-/object-schema-1.2.0.tgz#87de7af9c231826fdd68ac7258f77c429e0e5fcf"
integrity sha512-wdppn25U8z/2yiaT6YGquE6X8sSv7hNMWSXYSSU1jGv/yd6XqjXgTDJ8KP4NgjTXfJ3GbRjeeb8RTV7a/VpM+w==

"@istanbuljs/load-nyc-config@^1.0.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz#fd3db1d59ecf7cf121e80650bb86712f9b55eced"
Expand Down Expand Up @@ -4105,7 +4119,7 @@ get-caller-file@^2.0.1:
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e"
integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==

get-intrinsic@^1.0.2, get-intrinsic@^1.1.0, get-intrinsic@^1.1.1:
get-intrinsic@^1.0.2, get-intrinsic@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/get-intrinsic/-/get-intrinsic-1.1.1.tgz#15f59f376f855c446963948f0d24cd3637b4abc6"
integrity sha512-kWZrnVM42QCiEA2Ig1bG8zjoIMOgxWwYCEeNdwY6Tv/cOSeGpcoX4pXHfKUxNKVoArnrEr2e9srnAxxGIraS9Q==
Expand Down Expand Up @@ -4597,9 +4611,10 @@ internal-slot@^1.0.3:
resolved "https://registry.yarnpkg.com/internal-slot/-/internal-slot-1.0.3.tgz#7347e307deeea2faac2ac6205d4bc7d34967f59c"
integrity sha512-O0DB1JC/sPyZl7cIo78n5dR7eUSwwpYPiXRhTzNxZVAMUuB8vlnRFyLxdrVToks6XPLVnFfbzaVd5WLjhgg+vA==
dependencies:
get-intrinsic "^1.1.0"
has "^1.0.3"
side-channel "^1.0.4"
default-gateway "^6.0.0"
ipaddr.js "^1.9.1"
is-ip "^3.1.0"
p-event "^4.2.0"

ip-regex@^4.0.0:
version "4.3.0"
Expand Down
2 changes: 2 additions & 0 deletions packages/eslint-config-react-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

'use strict';

require('./patch');

// Inspired by https://github.com/airbnb/javascript but less opinionated.

// We use eslint-loader so even warnings are very visible.
Expand Down
3 changes: 2 additions & 1 deletion packages/eslint-config-react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"files": [
"base.js",
"index.js",
"jest.js"
"jest.js",
"patch.js"
],
"peerDependencies": {
"eslint": "^7.30.0"
Expand Down
11 changes: 11 additions & 0 deletions packages/eslint-config-react-app/patch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

// Fix eslint shareable config (https://github.com/eslint/eslint/issues/3458)
require('@rushstack/eslint-patch/modern-module-resolution');
17 changes: 17 additions & 0 deletions packages/react-scripts/config/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ const moduleFileExtensions = [
'jsx',
];

const moduleFederationConfigFiles = [
'modulefederation.config.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 +77,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 +106,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 +148,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
28 changes: 24 additions & 4 deletions packages/react-scripts/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ const getCacheIdentifier = require('react-dev-utils/getCacheIdentifier');
// @remove-on-eject-end
const createEnvironmentHash = require('./webpack/persistentCache/createEnvironmentHash');

const ExternalTemplateRemotesPlugin = require('external-remotes-plugin');

// Source maps are resource heavy and can cause out of memory issue for large source files.
const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';

Expand All @@ -58,6 +60,9 @@ const shouldInlineRuntimeChunk = process.env.INLINE_RUNTIME_CHUNK !== 'false';
const emitErrorsAsWarnings = process.env.ESLINT_NO_DEV_ERRORS === 'true';
const disableESLintPlugin = process.env.DISABLE_ESLINT_PLUGIN === 'true';

const shouldUseExternalTemplateRemotesPlugin =
process.env.EXTERNAL_TEMPLATE_REMOTES === 'true';

const imageInlineSizeLimit = parseInt(
process.env.IMAGE_INLINE_SIZE_LIMIT || '10000'
);
Expand Down Expand Up @@ -201,10 +206,7 @@ module.exports = function (webpackEnv) {
? 'static/js/[name].[contenthash:8].chunk.js'
: isEnvDevelopment && 'static/js/[name].chunk.js',
assetModuleFilename: 'static/media/[name].[hash][ext]',
// 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 @@ -322,6 +324,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 @@ -586,7 +593,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 @@ -763,6 +776,13 @@ module.exports = function (webpackEnv) {
},
},
}),
paths.appMFConfigFile &&
new webpack.container.ModuleFederationPlugin(
require(paths.appMFConfigFile)
),
paths.appMFConfigFile &&
shouldUseExternalTemplateRemotesPlugin &&
new ExternalTemplateRemotesPlugin(),
].filter(Boolean),
// Turn off performance processing because we utilize
// our own hints via the FileSizeReporter
Expand Down
1 change: 1 addition & 0 deletions packages/react-scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"eslint": "^7.30.0",
"eslint-config-react-app": "^6.0.0",
"eslint-webpack-plugin": "^2.5.4",
"external-remotes-plugin": "^1.0.0",
"file-loader": "^6.2.0",
"fs-extra": "^10.0.0",
"html-webpack-plugin": "5.3.2",
Expand Down