Skip to content
This repository was archived by the owner on Aug 4, 2021. It is now read-only.

Prepare for rollup-1.0 #124

Merged
merged 11 commits into from
Sep 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/node_modules
!test/sample/dts/node_modules
dist
test/**/*.out
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ language: node_js
node_js:
- "10"
- "8"
- "7"

58 changes: 48 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ See [rollup-plugin-babel](https://github.com/rollup/rollup-plugin-babel).
## Installation

```bash
npm install --save-dev rollup-plugin-typescript
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
Expand All @@ -23,31 +25,67 @@ 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.
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
* `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')
})
```

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

### TypeScript version
[TypeScript 2.6.2](https://github.com/Microsoft/TypeScript/wiki/Roadmap#26-october-2017) is used by default. Should your project require it, you can override the TypeScript version used for _transpiling the sources_.
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
typescript({
typescript: require('some-fork-of-typescript')
})
// 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
Emit-less types, see [#28](https://github.com/rollup/rollup-plugin-typescript/issues/28).
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).
Loading