1.1.0 • Published 2 years ago

react-cosmos-esbuild v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

React Cosmos ESbuild

ESbuild-compatible React Cosmos.

Installation

npm install @adamdickinson/react-cosmos-esbuild

or

yarn add @adamdickinson/react-cosmos-esbuild

Usage

If it's a simple enough build process, you can totally get away with just running:

yarn cosmos-esbuild

Doing so runs cosmos, as well as esbuild with a default, cosmos-compatible config.

However, a lot of esbuild-driven projects have some rather complex requirements, so this package accommodates that too. By specifying a esbuildConfigPath in your cosmos config, you can inject your own esbuild config in to adjust the esbuild config this package uses.

Sample cosmos.config.json:

{
  "esbuildConfigPath": "./scripts/config.js"
}

Sample config.js:

module.exports = {
  define: {
    'process.env.RUNNING_COSMOS', 'true'
  }
}

This config will then be used as the baseline config for the esbuild runner that is used to power cosmos as follows:

{
  ...config,
  bundle: true,
  entryPoints: [MAIN_TS_PATH],
  outfile: MAIN_JS_PATH,
  outdir: undefined
}

In other words, any custom config values for bundle, entryPoints, outfile and outdir will be overridden in order for the package to work with cosmos.

Got some things you'd like to see?

Spin up a PR! Standards are pretty high, but feedback is a cornerstone of any good pull request so expect much love for any contributions.