# module-federation-types-plugin

> This plugin merges declaration asset files from common microfrontend modules specified in the exposes object for the ModuleFederation plugin and created using the generated Webpack ts-loader into one declaration file. In addition, the plugin allows you to

Latest version **1.0.6** (published 2023-06-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install module-federation-types-plugin
pnpm add module-federation-types-plugin
yarn add module-federation-types-plugin
bun add module-federation-types-plugin
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2023-06-07 |
| First published | 2023-06-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 26.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Anatoly Ivashov |
| Maintainers | tonyshow |
| Keywords | module federation, module federation types, microfrontends, microfrontends types, webpack, type declaration, .d.ts, webpack types bundler, types |

## Links

- npm: https://www.npmjs.com/package/module-federation-types-plugin
- Repository: https://github.com/tony-show/module-federation-types-plugin
- Homepage: https://github.com/tony-show/module-federation-types-plugin#readme
- Issues: https://github.com/tony-show/module-federation-types-plugin/issues
- npm.io page: https://npm.io/package/module-federation-types-plugin

## Alternatives

- [raw-loader](https://npm.io/package/raw-loader.md) — 4.3M weekly downloads
- [plop](https://npm.io/package/plop.md) — 1.4M weekly downloads
- [webpack-deadcode-plugin](https://npm.io/package/webpack-deadcode-plugin.md) — 80.3K weekly downloads
- [@storybook/preact-vite](https://npm.io/package/@storybook/preact-vite.md) — 54.2K weekly downloads
- [vite-plugin-transform](https://npm.io/package/vite-plugin-transform.md) — 2.4K weekly downloads

## Recent versions

- 1.0.6 (latest) — 2023-06-07
- 1.0.5 — 2023-06-07
- 1.0.4 — 2023-06-07
- 1.0.3 — 2023-06-05
- 1.0.2 — 2023-06-05
- 1.0.1 — 2023-06-05
- 1.0.0 — 2023-06-05

## README

# Module Federation Types Plugin
Typing your microfrontends created with the Webpack Module Federation is easy! 🎉

# Description
This webpack plugin types the Webpack Module Federation microfrontends.

The plugin merges type declaration files (.d.ts) from common microfrontend modules, specified in the exposes object for the ModuleFederation plugin and created with the generated ts-loader (see configuration settings below), into one declaration file.

In addition, the plugin allows you to upload type declaration files (.d.ts) from the specified URLs to the microfrontends, in the remotes object for the ModuleFederation plugin.

# Options:

|Name|Type|Default|Description|
|:--:|:--:|:-----:|:----------|
|**`name`**|`String`|required option|Name of your app (like `name` option in ModuleFederation)|
|**`outDir`**|`String`|``types``|The path where the generated type declaration file will be saved in the project build folder (for the current application)|
|**`exposes`**|`Object`|`undefined`|The object `exposes` the entities you are sharing (like `exposes` option in ModuleFederation)|
|**`remotes`**|`Object`|`undefined`|The object `remotes` with url adreses to remoteEntry files of your microfrontends (like `remotes` option in ModuleFederation)|
|**`remoteTypesDir`**|`String`|`../../src/microfrontends/types`|The path to which the type declarations (.d.ts) files of your microfronts specified in the `remotes` option will be downloaded|
|**`clearOnStart`**|`String`|`undefined`|The path to the folder to be delete before build|
|**`clearOnEnd`**|`String`|undefined|The path to the folder to be delete after the build|


# Example configuration:
**In host app:**
```javascript
//webpack.config.ts
import ModuleFederationTypesPlugin from 'module-federation-types-plugin'

const appName = 'app'
const exposes = {
  './component': './src/component',
  './component_2': './src/component_2'
} // ModuleFederationTypesPlugin generate one file with types declaration for your exposes modules
const remotes = export const prodRemotes = {
  app1: 'app1@http://127.0.0.1:3000/remoteEntry.js',  // ModuleFederationTypesPlugin download app1.d.ts file from this URL
  app2: 'app2@http://127.0.0.1:3001/remoteEntry.js' // ModuleFederationTypesPlugin download app2.d.ts file from this URL
}

//...
  module: {
    rules: {
      test: /\.tsx?$/,
      exclude: /node_modules/,
      use: [
        {
          loader: 'ts-loader',
          options: {
            compilerOptions: {
              declaration: true, // generate type declaration files for all project
              declarationDir: 'types', // This folder with generated .d.ts files for all project may be delete with option clearOnStart in ModuleFederationTypesPlugin after build
            },
          },
        },
      ],
    }
  },
  plugins: [
    new ModuleFederationPlugin({
      name: appName,
      filename: 'remoteEntry.js',
      exposes: exposes,
      remotes: remotes,
    }),
    new ModuleFederationTypesPlugin({
      name: appName,
      outDir: `./types`,
      exposes: exposes,
      remotes: remotes,
      remoteTypesDir: './src/types',
      clearOnStart: 'build',
      clearOnEnd: 'types',
    }),
  ]
// ...
```

**After build**

`build/types` folder (generated .d.ts file)
```javascript
  // build/types/app.d.ts
  declare module "app/component" {
    //... component types
  }

  declare module "app/component_2" {
    //... component_2 types
  }
```

`src/types` folder (downloaded .d.ts files)
```javascript
  app1.d.ts
  app2.d.ts
```

---
_Source: https://npm.io/package/module-federation-types-plugin · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
