Security News
vlt Debuts New JavaScript Package Manager and Serverless Registry at NodeConf EU
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
rollup-plugin-fast-typescript
Advanced tools
A plugin that uses esbuild, swc or sucrase (you decide!) for blazing fast TypeScript transpilation.
A plugin that uses esbuild, swc or Sucrase (you decide!) for blazing fast TypeScript transpilation.
- This plugin requires Rollup version 4.0.0 or higher.
- This package is ESM-only and can only be used from an ESM configuration file (either
rollup.config.mjs
orrollup.config.js
withtype="module"
inpackage.json
. See Rollup docs for more detail).
tsconfig.json
is all you need.tsconfig.json
compatibility:
tsconfig.json#extends
:
compilerOptions#baseUrl
, compilerOptions#paths
, compilerOptions#rootDirs
and even compilerOptions#moduleSuffixes
!Use your favorite package manager. Mine is npm.
You must also make sure that the transpiler you plan to use is installed - the plugin does not install it for you.
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
The simpler, the better.
// rollup.config.js
import fastTypescript from 'rollup-plugin-fast-typescript'
export default {
...
plugins: [
fastTypescript('esbuild') // or 'swc' or 'sucrase'
]
}
This will load your project's tsconfig.json
and use the specified transformer to transpile your code to Javascript.
Starting with version 2.1.0, the plugin also exports these three convenience functions:
esbuild(tsconfig)
is an alias for fastTypescript('esbuild', tsconfig)
swc(tsconfig)
is an alias for fastTypescript('swc', tsconfig)
sucrase(tsconfig)
is an alias for fastTypescript('sucrase', tsconfig)
For example:
// rollup.config.js
import { swc } from 'rollup-plugin-fast-typescript'
export default {
...
plugins: [
swc() // Use swc to transpile TypeScript
]
}
rollup-plugin-fast-typescript
's parti pris is to mimic the behavior of the real TypeScript compiler as closely as possible (two obvious exceptions here are type checking and declaration files generation, since none of the supported transpilers support these features), so the plugin doest not offer any option to play with other than the choice of the transpiler to use and the tsconfig.json
settings to use.
fastTypescript(
transpiler: 'esbuild' | 'swc' | 'sucrase',
tsconfig?: boolean | string | TsConfigJson | (() => MaybePromise<boolean | string | TsConfigJson>)
)
esbuild(tsconfig?: boolean | string | TsConfigJson | (() => MaybePromise<boolean | string | TsConfigJson>))
swc(tsconfig?: boolean | string | TsConfigJson | (() => MaybePromise<boolean | string | TsConfigJson>))
sucrase(tsconfig?: boolean | string | TsConfigJson | (() => MaybePromise<boolean | string | TsConfigJson>))
transpiler
Type: 'esbuild' | 'swc' | 'sucrase'
Optional: no
When using the generic fastTypescript
export, you must specify the name of the transpiler to use.
Again, 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.
tsconfig
Type: boolean | string | TsConfigJson | (() => MaybePromise<boolean | string | TsConfigJson>)
Optional: yes
Default: true
Specifies how to resolve TypeScript options:
true
(the default) will load your project's tsconfig.json
file.
tsconfig.json
file to load (e.g., './tsconfig.prod.json'
) or the name of an installed npm package exposing a tsconfig.json
file (e.g., '@tsconfig/node16/tsconfig.json'
).TsConfigJson
object (note: the TsConfigJson
interface is re-exported from type-fest).false
or an empty string will cause the selected transpiler to use its own default settings.tsc
would have given the passed tsconfig.json
, no more, no less. Therefore, none of the supported transpilers specificities/unique features are exposed. In the simplest case, the transpiler is just a "get rid of type annotations" tool -- and a very fast one, for that matter.transform
API with settings derived from the passed tsconfig.json
. For example, TypeScript's target
setting is mapped to the transpiler's corresponding setting.'esm'
.
swc
does not handle Typescript's import assignments when targetting esm and will error out when it encounters one.The plugin may issue a few warnings during the build phase; here are their meaning.
Because none of the third-party transpilers the plugin uses under the hood is type-aware, some techniques or features often used in TypeScript are not properly checked and can cause mis-compilation or even runtime errors.
To mitigate this, you should set the isolatedModules
option to true in tsconfig and let your editor warn you when such incompatible constructs are used.
You should also run tsc --noEmit
sometime in your build steps to double check.
MIT
FAQs
A plugin that uses esbuild, swc or sucrase (you decide!) for blazing fast TypeScript transpilation.
The npm package rollup-plugin-fast-typescript receives a total of 6 weekly downloads. As such, rollup-plugin-fast-typescript popularity was classified as not popular.
We found that rollup-plugin-fast-typescript demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
Security News
Research
The Socket Research Team uncovered a malicious Python package typosquatting the popular 'fabric' SSH library, silently exfiltrating AWS credentials from unsuspecting developers.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.