1.0.25 • Published 2 years ago

co-react-webpack-build v1.0.25

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

React Module Federation Library

This package pre-configures webpack to work with module federation with react.

Configuration

Changes on the configuration can be done through the package.json file, as well as indicate which components should be exposes or consume.

PropertyDefault ValuetypeDescription
namen/astringThis value will be used as package name in the federation url. Example: for the name 'package-name' the url will be: packageName@http://localhost:1234/remoteEntry.js
sourceFolder./srcstring
mainindex.tsstringEntry file name. Webpack will look for it in the sourceFolder
hostlocalhoststringHost to use. This will set webpack devServer.host
port9000intPort to use. This will set webpack devServer.port
exposes objectA list of components to expose for module federation. The format should be: { "./ComponentName": "/path/to/component" }
remotes objectA list of federated modules to consume. The format should be: { "ComponentName": "exposeName@http://host/remoteEntry.js" }
shared objectA list of shared components. The format should be: { "react": { "singleton": true, "eager": true } } The requiredVersion field will be retrieved from the dependency version
allowedHostsautoarray/stringAllows you to whitelist services that are allowed to access the dev server. See webpack documentation

Example of a package.json

{
  "name": "test-app",
  "version": "1.0.0",
  "description": "Test App",
  "main": "index.ts",
  "port": 9091,
  "scripts": {
    "start": "co-dev-server",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Author",
  "license": "ISC",
  "homepage": "https://github.com/some-user/test-app#readme",
  "devDependencies": {
    "@types/jest": "^27.4.0",
    "@types/react": "^17.0.38",
    "@types/react-dom": "^17.0.11",
    "typescript": "^4.5.5"
  },
  "dependencies": {
    "co-react-webpack-build": "^1.0.22",
    "react": "^17.0.2",
    "react-dom": "^17.0.2"
  },
  "remotes": {
    "RemoteComponent": "remoteComponent@http://localhost:9091/remoteEntry.js"
  },
  "exposes": {
    "./TestComponent": "./components/TestComponent/index.tsx"
  },
  "shared": {
    "react": {
      "singleton": true,
      "eager": true
    },
    "react-dom": {
      "singleton": true,
      "eager": true
    }
  }
}