Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • C create-react-app
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1,547
    • Issues 1,547
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 417
    • Merge requests 417
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Meta
  • create-react-app
  • Merge requests
  • !12284

Support Webpack Module Federation

  • Review changes

  • Download
  • Email patches
  • Plain diff
Open Administrator requested to merge github/fork/HewlettPackard/main into main Apr 13, 2022
  • Overview 20
  • Commits 11
  • Pipelines 0
  • Changes 6

Created by: raspy8766

Module Federation Support

Description

This PR aims to support the Webpack 5 module federation plugin natively in CRA. Micro-frontends are becoming a more prevalent form of UI development for the enterprise environment. We love what create-react-app provides, but in order to get it working at the moment, we rely on these forked changes. Hopefully this PR has what you're looking for, if not I'm happy to make additional accommodations and open to suggestions.

Proposed Changes

  • Add a new optional setupModuleFederation.js file that manages the webpack Module Federation plugin
  • When the setupModuleFederation.js file is present, use the Module Federation plugin
  • Since Micro-frontend apps do not typically have their own index.html (unless they're using iframes), the index.html file along with the public folder are now optional.

Testing

Setup

  1. Execute the following bash script which performs the following:
    • Initializes a new CRA mfe app repo
    • Clones down and installs the forked repo
    • Installs local react-scripts from forked repo
yarn create react-app mfe-app && \
git clone https://github.com/HewlettPackard/create-react-app.git && \
yarn --cwd="./create-react-app" && \
yarn --cwd="./mfe-app" add file:../create-react-app/packages/react-scripts

Negative Test

  1. In the mfe-app repo, run yarn start
  2. Navigate to http://localhost:3000/webpack-dev-server and note the files listed appear as normal

Positive Test

  1. Create a src/setupModuleFederation.js file with the following contents:
module.exports = {
  name: 'test',
  library: { type: 'var', name: 'test' },
  filename: 'remoteEntry.js',
  exposes: { '.': './src/App.js' }
}
  1. Navigate to the mfe-app repo
  2. Delete the public/index.html file (optional)
  3. Run yarn start
  4. Navigate to http://localhost:3000/webpack-dev-server and notice the remoteEntry.js file

Screenshots

Webpack served assets:

image

remoteEntry.js file:

image
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/HewlettPackard/main