0.2.0-alpha.1 • Published 11 months ago

@appshell/config v0.2.0-alpha.1

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

Appshell CI

@appshell/config

Utitliy for generating a global runtime manifest for Webpack Module federation micro-frontends.

Working examples can be found here.

Getting Started

To begin, you'll need to install @appshell/config:

npm install @appshell/config --save-dev

or

yarn add -D @appshell/config

or

pnpm add -D @appshell/config

The primary export from this package is the generate function. It is given a configs dir to process and produces a global runtime manifest.

import { generate } from '@appshell/config';

const manifest = generate<MyMetadata>(process.env.APPSHELL_CONFIGS_DIR);

Sample APPSHELL_CONFIGS_DIR

Where does the content of APPSHELL_CONFIGS_DIR come from?

Each micro-frontend configured to use @appshell/manifest-webpack-plugin emits it's configuration to the configs directory at build time, which is subsequently processed with this utility to reflect the current runtime environment.

Sample content from APPSHELL_CONFIGS_DIR:

{
  "remotes": {
    "CraModule/App": {
      "url": "${CRA_MFE_URL}",
      "metadata": {
        "route": "/cra",
        "displayName": "Example App",
        "displayGroup": "${CRA_MFE_DISPLAY_GROUP}",
        "order": 10,
        "icon": "ViewList"
      },
      "id": "3eb81a0c"
    }
  },
  "module": {
    "exposes": {
      "./App": "./src/App"
    },
    "filename": "remoteEntry.js",
    "name": "CraModule",
    "shared": {
      "react": {
        "singleton": true,
        "requiredVersion": "^18.2.0"
      },
      "react-dom": {
        "singleton": true,
        "requiredVersion": "^18.2.0"
      }
    }
  }
}

How does my runtime environment get reflected in the global runtime manifest?

Note the variable expansion syntax ${CRA_MFE_URL}. When generate is called the actual runtime environment values are injected and all configurations are merged into a global runtime manifest.

Sample global runtime manifest produced by the generate function:

{
  "remotes": {
    "CraModule/App": {
      "id": "3eb81a0c",
      "url": "http://localhost:3001/remoteEntry.js",
      "scope": "CraModule",
      "module": "./App",
      "metadata": {
        "route": "/cra",
        "displayName": "Example App",
        "displayGroup": "main",
        "order": 10,
        "icon": "ViewList"
      }
    },
    "VanillaModule/Vanilla": {
      "id": "8232ce86",
      "url": "http://localhost:3002/remoteEntry.js",
      "scope": "VanillaModule",
      "module": "./Vanilla",
      "metadata": {
        "route": "/vanilla",
        "displayName": "Example React App",
        "displayGroup": "main",
        "order": 10,
        "icon": "ViewList"
      }
    }
  },
  "modules": {
    "Appshell": {
      "name": "Appshell",
      "shared": {
        "react": {
          "singleton": true,
          "requiredVersion": "^18.2.0"
        },
        "react-dom": {
          "singleton": true,
          "requiredVersion": "^18.2.0"
        }
      }
    },
    "CraModule": {
      "exposes": {
        "./App": "./src/App"
      },
      "filename": "remoteEntry.js",
      "name": "CraModule",
      "shared": {
        "react": {
          "singleton": true,
          "requiredVersion": "^18.2.0"
        },
        "react-dom": {
          "singleton": true,
          "requiredVersion": "^18.2.0"
        }
      }
    },
    "VanillaModule": {
      "exposes": {
        "./Vanilla": "./src/App"
      },
      "filename": "remoteEntry.js",
      "name": "VanillaModule",
      "shared": {
        "react": {
          "singleton": true,
          "requiredVersion": "^18.2.0"
        },
        "react-dom": {
          "singleton": true,
          "requiredVersion": "^18.2.0"
        }
      }
    }
  }
}

This global runtime manifest can be consumed by your micro-frontend Appshell host and used to configure the Appshell accordingly.

What if I want to generate the manifest by a startup script instead?

This functionality is exposed by the @appshell/cli package. You can simply call appshell generate manifest --configsDir /path/to/appshell_configs to produce the global runtime manifest on startup.

0.1.7-alpha.0

11 months ago

0.2.0-alpha.1

11 months ago

0.1.6-alpha.2

11 months ago

0.1.6

11 months ago

0.1.6-alpha.1

1 year ago

0.1.6-alpha.0

1 year ago

0.1.5

1 year ago

0.1.5-alpha.0

1 year ago

0.1.4

1 year ago

0.1.4-alpha.0

1 year ago

0.2.0-alpha.0

1 year ago

0.1.0-alpha.0

1 year ago

0.1.3

1 year ago

0.1.3-alpha.0

1 year ago

0.1.2

1 year ago

0.1.2-alpha.3

1 year ago

0.1.2-alpha.2

1 year ago

0.1.2-alpha.1

1 year ago

0.1.2-alpha.0

1 year ago

0.1.1

1 year ago

0.1.1-alpha.2

1 year ago

0.1.1-alpha.1

1 year ago

0.1.1-alpha.0

1 year ago

0.1.0

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago