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

Package detail

rollup-plugin-typescript

rollup124.7kMITdeprecated1.0.1

This package has been deprecated and is no longer maintained. Please use @rollup/plugin-typescript.

Seamless integration between Rollup and TypeScript.

rollup-plugin, typescript, es2015

readme

rollup-plugin-typescript

Build Status npm-version npm-monthly-downloads npm-dependencies

Seamless integration between Rollup and Typescript.

Why?

See rollup-plugin-babel.

Installation

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

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

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

The plugin loads any compilerOptions from the tsconfig.json file by default. Passing options to the plugin directly overrides those options:

...
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:

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

    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. See also here.

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.

// 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 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.

changelog

rollup-plugin-typescript changelog

1.0.1

2019-03-24

  • Update dependencies (#136)

1.0.0

2018-09-16

  • Major update for TypeScript 2/3, Rollup 1 compatibility, lots of fixes (#124)
  • Require TypeScript as peer dependency (#121)
  • Also test on Node 10 (#119)
  • Fix example in readme (#98)

0.8.1

  • Ignore typescript-helpers in source maps (#61)

0.8.0

  • Fix the rollup breaking change with paths (#52)
  • Don't fail without source maps (#57)

0.7.7

  • Add missing __assign helper (#49)

0.7.6

  • Ignore the declaration option (#45)
  • Disable strictNullChecks with a warning for TypeScript versions that don't support it (#46)

0.7.5

  • Ensure NPM doesn't ignore typescript-helpers

0.7.4

  • Resolve typescript-helpers to a file in the filesystem.

0.7.3

  • Update Tippex to ^2.1.1

0.7.2

  • Don't error if both sourceMap and inlineSourceMap are specified

0.7.1

  • No plugin specific options should be forwarded to TypeScript

0.7.0

  • Use compilerOptions from tsconfig.json if found (#39)

0.6.1

  • Upgrade Tippex to ^2.1.0
  • Upgrade TypeScript to ^1.8.9

0.6.0

  • Upgrade to TypeScript ^1.8.7
  • Update __awaiter helper to support TypeScript 1.8.x (#32)
  • Update ts.nodeModuleNameResolver to support both 1.7.x and 1.8.x (#31)

0.5.0

  • Do not duplicate TypeScript's helpers (#24)
  • Handle export abstract class (#23)

0.4.1

  • Does not attempt resolve or transform .d.ts files (#22)

0.4.0

  • Work around TypeScript 1.7.5's transpilation issues (#9)
  • Overridable TypeScript version when transpiling (#4)
  • Add jsx support (#11)

0.3.0

  • Author plugin in TypeScript
  • Report diagnostics
  • Resolve identifiers using ts.nodeModuleNameResolver

0.2.1

  • Upgrade to TypeScript ^1.7.5
  • Enable source maps per default

0.2.0

  • Use (prerelease version of) TypeScript 1.7.0 to generate ES5 while preserving ES2015 imports for efficient bundling.

0.1.0

  • Initial release