This is a template repo for creating a micro frontend react app.
Includes support for:
- React with TypeScript/JavaScript (preferably stick to TypeScript)
- ESLint with custom rules added from @badboyku/eslint-config-badboyku
- Jest with jest-dom
- Husky's pre-commit hook that will run linter and tests
- Webpack with Module Federation Plugin
- Install dependencies:
yarn install
ornpm install
- Start the app:
yarn start
ornpm start
- Browser should automatically open to http://localhost:8080
NOTE: App will be served from webpack-dev-server's default port 8080, which can be changed by following the .env.example in the repo.
This plugin is used to help bundle multiple builds into one build.
There are some options that need to be set in webpack.config.js
file:
-
name
- this is used for your application nameExample:
name: 'my_app'
-
remotes
- this is used to set up your app to have remote appsExample:
remotes: { this_app: 'this_app@http://localhost:8081/remoteEntry.js', that_app: 'that_app@http://localhost:8082/remoteEntry.js', }
-
exposes
- this is used to set up your app to expose one or more componentsExample:
exposes: { './ThisComponent': './src/components/ThisComponent', './ThatComponent': './src/components/ThatComponent', }
See https://github.com/module-federation/module-federation-examples as reference examples
ESLint has been set up with using the config from: @badboyku/eslint-config-badboyku
- To run eslint:
yarn lint
ornpm run lint
- To run eslint with fix:
yarn lint:fix
ornpm run lint:fix
NOTE: You are able to override a rule by updating the rules inside the .eslintrc.js
file.
Example:
rules: {
'no-console': 'error',
},
Prettier has been configured to help format css, scss, json files
- To run prettier:
yarn prettier
ornpm run prettier
- To run prettier with fix:
yarn prettier:fix
ornpm run prettier:fix
Jest has been set up with coverage needing at least 80%. We are following industry standards to keep test files and snapshots in the src folder.
- To run jest:
yarn test
ornpm test
- To run jest and update snapshots:
yarn test -u
ornpm test -u
- To run jest test coverage:
yarn test:coverage
ornpm test:coverage
- To run jest watch mode:
yarn test:watch
ornpm test:watch
In the src
folder, let's try to keep a components
, pages
, and routes
folder, in order to have a common folder structure for each MFE app. Apart from that, create folders to support your application.