Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

esbuild-runner

folke353.3kApache License 2.02.2.2TypeScript support: included

Super-fast on-the-fly transpilation of modern JS, TypeScript and JSX using esbuild

esbuild, typescript, commonjs, jest, esnext, cjs, node, nodejs, es6, esm, ts-node

readme

:zap: Esbuild Runner (esr)

Super-fast on-the-fly transpilation of modern JS, TypeScript and JSX using esbuild.

esr makes it easy to run arbitrary code or tests without needing to build your whole project. It's a great way to improve your development workflow.

✨ Usage

The easiest way to use esbuild-runner is to install it globally and use the included esr binary.

$ esr hello-world.ts

Alternatively, you can require esbuild-runner within any nodejs process to include realtime transpilation:

$ node -r esbuild-runner/register hello-world.ts

In order to use esbuild-runner with Jest, you need to configure a Jest transform in your jest.config.js

module.exports = {
  transform: {
    "\\.ts$": "esbuild-runner/jest",
  },
}

VSCode Debugging

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Debug with esbuild-runner",
      "program": "${workspaceFolder}/hello-world.ts",
      "runtimeArgs": [
        "-r",
        "esbuild-runner/register"
      ],
      "request": "launch",
      "sourceMaps": true,
      "skipFiles": [
        "<node_internals>/**"
      ],
      "type": "pwa-node"
    }
  ]
}

⚙️ Configuration

esr provides two different ways to transpile your code:

  • bundling (default): this transpiles the script and all its dependencies in typically one invocation of esbuild. Dependencies defined in package.json or node_modules will never be transpiled. Running esr will always transpile the code. No caching is used.
  • transform (--cache): this method will invoke esbuild for every source file, but will cache the result. This means that the initial run will be slower, but after that, only changed source files will be transpiled.
$ bin/esr.js --help
Usage: esr [options] <source-file> [file-options]

  --cache       Transform on a file per file basis and cache code
  --clearCache  Clear transform cache
  --help|-h     Display this help message

To customize the options passed to esbuild, you can create an esbuild-runner.config.js file in the current directory or one of the ancestor directories.

// example esbuild-runner.config.js
module.exports = {
  type: "bundle", // bundle or transform (see description above)
  esbuild: {
    // Any esbuild build or transform options go here
    target: "esnext",
  },
}

📦 Installation

Simply install the esbuild-runner npm package using your favorite package manager.

  • globally ...
$ npm install -g esbuild-runner
  • ... or locally in your project
$ npm add --dev esbuild-runner

👋 Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

⚖ License

Apache 2.0

changelog

2.2.1 (2021-08-30)

2.2.0 (2021-06-04)

Features

  • ✨ added support for custom loaders #24 (ad3268e)

2.1.0 (2021-06-01)

Features

  • ✨ allow overriding esbuild.external #23 (801eb20)

2.0.0 (2021-05-29)

⚠ BREAKING CHANGES

  • 💥 ♻️ renamed the config file from esbuild.config.js -> esbuild-runner.config.js

Code Refactoring

  • 💥 ♻️ renamed the config file from esbuild.config.js -> esbuild-runner.config.js (728518d)

1.4.0 (2021-05-26)

Features

  • ✨ added config for passing build / transform options to the api #14 (200447e)
  • ✨ esbuild.config.js #14 #19 (9dfb19f)

Bug Fixes

  • 🐛 added esbuild as a peer dependency. Fixes #16 (8656874)

1.3.2 (2020-12-14)

Bug Fixes

  • 🐛 use rmdirSync instead of rmSync for compatibility with older nodejs versions (a57482a)

1.3.1 (2020-12-09)

Bug Fixes

  • 🐛 show message and exit, after clearing cache (91aafc0)

1.3.0 (2020-12-09)

Features

  • ✨ added esbuild transform --cache (4ca2415)
  • ✨ added option to use transform with caching instead of bundling to the API (9345b78)
  • ✨ enable support for nextjs by transpiling .js files (5bcc8be)

1.2.0 (2020-12-09)

Features

  • ✨ added support for source maps (3435f7e)

1.1.1 (2020-12-07)

Bug Fixes

  • 🐛 renamed esn.js to esr.js (4caeafd)

1.1.0 (2020-12-07)

Features

  • ✨ added Jest transform module (6122523)
  • ✨ allow node -r es-node/register to automatically transpile source code (7a05c58)
  • ✨ initial version 🎉 (4669746)