JSPM

rollup-plugin-fast-typescript

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 18
  • Score
    100M100P100Q35183F
  • License MIT

A plugin that uses esbuild, swc or sucrase (you decide!) for blazing fast TypeScript transpilation, leaving the tree-shaking and bundling tasks to Rollup.

Package Exports

  • rollup-plugin-fast-typescript

Readme

rollup-plugin-fast-typescript

A plugin that uses esbuild, swc or sucrase (you decide!) for blazing fast TypeScript transpilation, leaving the tree-shaking and bundling tasks to Rollup (see why).

Installation

Use your favorite package manager (mine is npm). You must also make sure that at least one of esbuild, swc or sucrase is installed - the plugin does not install them for you.

⚠ This package is ESM-only and cannot be used in a CommonJS project without --bundleConfigAsCjs.

# for esbuild:
npm install --save-dev rollup-plugin-fast-typescript esbuild

# for swc:
npm install --save-dev rollup-plugin-fast-typescript @swc/core

# for sucrase:
npm install --save-dev rollup-plugin-fast-typescript sucrase

Usage

The simpler, the better.

// rollup.config.js
import typescript from 'rollup-plugin-fast-typescript'

export default {
  ...
  plugins: [
    typescript()
  ]
}

This will load your project's tsconfig.json and use esbuild to transpile your code to Javascript.

Options

rollup-plugin-fast-typescript's parti pris is to look like the real TypeScript as much as possible, so the plugin doest not offer any option to play with, other than the choice of which transpiler to use and which tsconfig file to load.

export default {
  plugins: [
    typescript(tsconfig, transpiler)
  ]
}

tsconfig?: boolean | string | TsConfigJson | (() => MaybePromise<boolean | string | TsConfigJson>) = true

Specifies how to resolve TypeScript options:

  • true (default) loads your project's tsconfig.json file.
  • false will call the transpiler with an empty tsconfig (said otherwise: the transpiler will apply its own default settings).
  • a string is assumed to be the path to the tsconfig file to use (e.g., './tsconfig.dev.json'), or the name of an installed npm package exposing a tsconfig file (e.g., '@tsconfig/node16/tsconfig.json').
  • an object is assumed to be a TsConfigJson object.
  • finally, if this parameter is a function, it may return any of the above, or a promise to any of the above.

transpiler?: 'esbuild' | 'swc' | 'sucrase' = 'esbuild'

The name of the transpiler to use. Default is 'esbuild'.

Remember that this plugin does not ship with, nor will it install for you, any of these transpilers; it is your responsibility to install the tool you plan to use.

Considerations

Why let Rollup do the tree-shaking and bundling?, you may ask.

IMHO, Rollup is still the best at tree-shaking and bundling: it offers the more control on what can be done and, when configured properly, emits the best code possible with very little bloat.

So the choice here is to trade some speed in exchange for power and precision. I call this is a reasonable choice.

Notes

rollup-plugin-fast-typescript tries to mimic TypeScript behavior as closely as possible.

Enjoy!