JSPM

rollup-plugin-fast-typescript

0.1.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 16
  • Score
    100M100P100Q35112F
  • 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).

Warning!

This plugin is at a very early stage and should be considered only out of curiosity or for testing.

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.

# 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 be as transparent 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 | (() => boolean | string | TsConfigJson | Promise<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 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'd say this is a reasonable choice.

Notes

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

Enjoy!