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

@planningcenter/module-federation-builder

v0.0.1-beta.2

Published

`@planningcenter/module-federation-builder` is a builder helper function that will use esbuild and rollup to generate files for your library for use with Module Federation.

Downloads

8

Readme

Module Federation Builder

@planningcenter/module-federation-builder is a builder helper function that will use esbuild and rollup to generate files for your library for use with Module Federation.

Usage

yarn add -D @planningcenter/module-federation-builder

To use:

import build from "@planningcenter/module-federation-builder"

build({
  // these are the imports that will be exposed and what files are their source.
  exposes: {
    "./": "./src/index.ts",
    "./Box": "./src/Box/index.ts",
  },
  // where the files will be built to
  outputPath: "dist",
  // peer dependencies that will be externalized. These need to be provided via the importmap.
  peerDependencies: ["react", "react-dom"],
  // dependencies that can use a shared dependency with the consuming apps.
  sharedDependencies: ["zustand"],
  // exports from shared dependencies that are not needed (and not exposed)
  skip: ["zustand/context"],
})

API

type RollupModuleFederationOptions = {
  /**
	Dev mode skips some of the minimization and optimization for
	ease of understanding in development environments. It also adds some logging
	of key processes for clarity.
	defaults to `false`
	**/
  dev?: boolean
  /**
	`exposes` is the endpoints that are exposes for import. For instance,
	a key of './' will be allow the end user to import like
	`import foo from 'my-library`, where a key of './Box' will allow an import
	like `import Box from 'my-library/Box`. Using more exposes allow consuming
	apps to be more selective of what parts of a library they use so that they
	can allow end users to only load what they are actually using.
	The value associated is the relative path to the file (from the base in the
	tsconfig file).

	example:
		exposes: {
	      './': './src/index.ts',
	      './Box': './src/Box/index.ts',
	      './Button': './src/Button/index.ts',
	      './ThemeProvider': './src/ThemeProvider/index.ts',
	    }
	**/
  exposes: { [key: string]: string }
  /**
	the output directory where files will be generated to.
	Generally the same as the output directory in the config.
	**/
  outputPath: string
  /**
	a list of the peerDependencies that are required to be exposed and defined
	by the consuming app. It is very possible that we could just infer this from
	the package.json, but for now, I am manually putting this here so that we can
	be a bit more explicit.
	**/
  peerDependencies?: string[]
  /**
	sharedDependencies are the names of imports that you identify as libraries
	that you might want to share a version other than the version defined inside
	the app. This is most often used by consuming apps for sharing peer
	dependencies from a library (like react). It can also be used to share a
	version of a shared library for optimization. For instance, you might have
	a minimum version of `moment-js` that is required for your library, but
	apps are most likely going to be using a version themselves.
	Adding that library as a sharedDependency will share a
	file of that library for a standard version, but it will default to using
	the version set up in the app if it is shared. This is an optional
	optimization and is often not needed. If issues arise from different versions
	not working (a singleton is needed), then use peerDependencies.
	**/
  sharedDependencies?: string[]
  /**
	If you want to not build certain parts of a shared library, then you can add
	part of the exported files to `skip` to exclude them from the build. This
	is an optimization, but can often help to resolve problems when libraries
	export parts of their libraries which are not ESM compatible (designed for
	server side code).
	**/
  skip?: string[]
  /**
	The path to your tsconfig file.
	defaults to  "./tsconfig.json"
	**/
  tsConfigPath?: string
  /**
	The workspaceRoot is the root folder to where to load files from. defaults
	to the current root folder of the rollup config.
	**/
  workspaceRoot?: string
}

function build(options: RollupModuleFederationOptions): Promise<void>