# rollup-plugin-typescript

> Seamless integration between Rollup and TypeScript.

Latest version **1.0.1** (published 2019-03-24) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install rollup-plugin-typescript
pnpm add rollup-plugin-typescript
yarn add rollup-plugin-typescript
bun add rollup-plugin-typescript
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2019-03-24 |
| First published | 2015-11-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 28 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 322 |
| Author | Oskar Segersvärd |
| Maintainers | paulbgd, rich_harris, trysound, victorystick |
| Keywords | rollup-plugin, typescript, es2015 |

## Links

- npm: https://www.npmjs.com/package/rollup-plugin-typescript
- Repository: https://github.com/rollup/rollup-plugin-typescript
- Issues: https://github.com/rollup/rollup-plugin-typescript/issues
- npm.io page: https://npm.io/package/rollup-plugin-typescript

## Dependencies (2)

- [resolve](https://npm.io/package/resolve.md) ^1.10.0
- [rollup-pluginutils](https://npm.io/package/rollup-pluginutils.md) ^2.5.0

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2019-03-24
- 1.0.0 — 2018-09-16
- 0.8.1 — 2016-08-17
- 0.8.0 — 2016-08-17
- 0.7.7 — 2016-07-18
- 0.7.6 — 2016-06-19
- 0.7.5 — 2016-04-25
- 0.7.3 — 2016-04-19
- 0.7.2 — 2016-04-19
- 0.7.1 — 2016-04-19
- 0.7.0 — 2016-04-14
- 0.6.1 — 2016-04-01
- 0.6.0 — 2016-03-07
- 0.5.0 — 2016-01-23
- 0.4.1 — 2016-01-22
- … 5 more at https://npm.io/package/rollup-plugin-typescript/versions

## README

# rollup-plugin-typescript
[![Build Status](https://travis-ci.org/rollup/rollup-plugin-typescript.svg?branch=master)](https://travis-ci.org/rollup/rollup-plugin-typescript)
![npm-version](https://img.shields.io/npm/v/rollup-plugin-typescript.svg?maxAge=2592000)
![npm-monthly-downloads](https://img.shields.io/npm/dm/rollup-plugin-typescript.svg?maxAge=2592000)
![npm-dependencies](https://img.shields.io/david/rollup/rollup-plugin-typescript.svg?maxAge=2592000)

Seamless integration between Rollup and Typescript.

## Why?
See [rollup-plugin-babel](https://github.com/rollup/rollup-plugin-babel).

## Installation

```bash
npm install --save-dev rollup-plugin-typescript typescript tslib
```

Note that both `typescript` and `tslib` are peer dependencies of this plugin that need to be installed separately.

## Usage

```js
// rollup.config.js
import typescript from 'rollup-plugin-typescript';

export default {
  input: './main.ts',
  plugins: [
    typescript()
  ]
}
```

The plugin loads any [`compilerOptions`](http://www.typescriptlang.org/docs/handbook/compiler-options.html) from the `tsconfig.json` file by default. Passing options to the plugin directly overrides those options:

```js
...
export default {
  input: './main.ts',
  plugins: [
      typescript({lib: ["es5", "es6", "dom"], target: "es5"})
  ]
}
```

The following options are unique to `rollup-plugin-typescript`:

* `options.include` and `options.exclude` (each a minimatch pattern, or array of minimatch patterns), which determine which files are transpiled by Typescript (all `.ts` and `.tsx` files by default).

* `tsconfig` when set to false, ignores any options specified in the config file. If set to a string that corresponds to a file path, the specified file will be used as config file.

* `typescript` overrides TypeScript used for transpilation:
  ```js
  typescript({
    typescript: require('some-fork-of-typescript')
  })
  ```

* `tslib` overrides the injected TypeScript helpers with a custom version
  ```js
  typescript({
    tslib: require('some-fork-of-tslib')
  })
  ```

### TypeScript version
Due to the use of `tslib` to inject helpers, this plugin requires at least [TypeScript 2.1](https://github.com/Microsoft/TypeScript/wiki/Roadmap#21-december-2016). See also [here](https://blog.mariusschulz.com/2016/12/16/typescript-2-1-external-helpers-library#the-importhelpers-flag-and-tslib).

### Importing CommonJS
Though it is not recommended, it is possible to configure this plugin to handle imports of CommonJS files from TypeScript. For this, you need to specify `CommonJS` as the module format and add `rollup-plugin-commonjs` to transpile the CommonJS output generated by TypeScript to ES Modules so that rollup can process it.

```js
// rollup.config.js
import typescript from 'rollup-plugin-typescript';
import commonjs from 'rollup-plugin-commonjs';

export default {
  input: './main.ts',
  plugins: [
    typescript({module: 'CommonJS'}),
    commonjs({extensions: ['.js', '.ts']}) // the ".ts" extension is required
  ]
}
```

Note that this will often result in less optimal output.

## Issues
This plugin will currently **not warn for any type violations**. This plugin relies on TypeScript's [transpileModule](https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#a-simple-transform-function) function which basically transpiles TypeScript to JavaScript by stripping any type information on a per-file basis. While this is faster than using the language service, no cross-file type checks are possible with this approach.

This also causes issues with emit-less types, see [#28](https://github.com/rollup/rollup-plugin-typescript/issues/28).

---
_Source: https://npm.io/package/rollup-plugin-typescript · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
