npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@pixability-ui/federated-types

v0.2.0

Published

share typings for your federated typescript packages around your mono-repo

Downloads

9,149

Readme

What is this for?

With Webpack 5's ModuleFederationPlugin, module federation is easy to implement. Coupling it with a mono-repo is powerful, but if your project uses TypeScript, it's tedious to manually create/maintain ambient type definitions for your packages so TypeScript can resolve the dynamic imports to their proper types. While using @ts-ignore on your imports works, it is a bummer to lose intellisense and type-checking capabilities.

This package exposes a node CLI command called make-federated-types. Once installed, you can run that command within a package, and it will write a typings file for your package into you node_modules directory that will be resolved by the TypeScript compiler.

How is this used?

You'll need to install this module with either NPM or yarn:

yarn add @pixability-ui/federated-types

You'll also need to place a federation.config.json in each package being federated. It will contain the remote name and exported members. These properties are used in Webpack's ModuleFederationPlugin configuration object. An example:

federation.config.json

{
    "name": "app2",
    "exposes": {
        "./Button": "./app2/Button"
    }
}

It's recommended that you spread these properties into your ModuleFederationPlugin configuration, like so:

webpack.config.js


const deps = require('../package.json').dependencies;
const federationConfig = require('./federation.config.json');

module.exports = {
    ...

    plugins: [
        new ModuleFederationPlugin({
            ...federationConfig,
            filename: "remoteEntry.js",
            shared: {
                ...deps,
            },
        }),
    ],

    ...
}

Then you can call make-federated-types from your scripts block in your package's package.json file:

package.json

scripts: {
    "make-types": "make-federated-types"
}

This will write new package to the node_modules/@types/__federated_types in your project. Since TypeScript will resolve typings in the node_modules/@types directory by default, you won't have to set up any other resolution or pathing in your tsconfig files to start using your typings.

If you would rather specify a directory in which to write the typing files, you can pass an --outputDir parameter to the command like so:

package.json

scripts: {
    "make-types": "make-federated-types --outputDir ../../my_types/"
}

package.json

If you would like to specify custom path to the config, you can pass --config parameter like so:

scripts: {
    "make-types": "make-federated-types --config ./path/to/my/config.json --outputDir ../../my_types/"
}