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

Commit 9a0eb1d

Browse files
authored
Prepare for rollup-1.0 (#124)
* Check for existence of tsconfig before trying to load it * Add node 7 tests to CI * Test tslib can be overridden * Update readme * Make tests run with rollup 1.0 * Support dynamic imports, remove tslib from source-maps * Remove unused externals * Test that module type is checked, test that module type is case insensitive * Clarify how to pass options in readme * Allow specifying tsconfig path * Make it possible to transpile CommonJS imports
1 parent bc32b66 commit 9a0eb1d

File tree

16 files changed

+1086
-831
lines changed

16 files changed

+1086
-831
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/node_modules
2+
!test/sample/dts/node_modules
23
dist
34
test/**/*.out

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ language: node_js
22
node_js:
33
- "10"
44
- "8"
5+
- "7"
56

README.md

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ See [rollup-plugin-babel](https://github.com/rollup/rollup-plugin-babel).
1212
## Installation
1313

1414
```bash
15-
npm install --save-dev rollup-plugin-typescript
15+
npm install --save-dev rollup-plugin-typescript typescript tslib
1616
```
1717

18+
Note that both `typescript` and `tslib` are peer dependencies of this plugin that need to be installed separately.
19+
1820
## Usage
1921

2022
```js
@@ -23,31 +25,67 @@ import typescript from 'rollup-plugin-typescript';
2325

2426
export default {
2527
input: './main.ts',
26-
2728
plugins: [
2829
typescript()
2930
]
3031
}
3132
```
3233

33-
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.
34+
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:
35+
36+
```js
37+
...
38+
export default {
39+
input: './main.ts',
40+
plugins: [
41+
typescript({lib: ["es5", "es6", "dom"], target: "es5"})
42+
]
43+
}
44+
```
3445

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

3748
* `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).
3849

39-
* `tsconfig` when set to false, ignores any options specified in the config file
50+
* `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.
51+
52+
* `typescript` overrides TypeScript used for transpilation:
53+
```js
54+
typescript({
55+
typescript: require('some-fork-of-typescript')
56+
})
57+
```
4058

41-
* `typescript` overrides TypeScript used for transpilation
59+
* `tslib` overrides the injected TypeScript helpers with a custom version
60+
```js
61+
typescript({
62+
tslib: require('some-fork-of-tslib')
63+
})
64+
```
4265

4366
### TypeScript version
44-
[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_.
67+
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).
68+
69+
### Importing CommonJS
70+
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.
4571

4672
```js
47-
typescript({
48-
typescript: require('some-fork-of-typescript')
49-
})
73+
// rollup.config.js
74+
import typescript from 'rollup-plugin-typescript';
75+
import commonjs from 'rollup-plugin-commonjs';
76+
77+
export default {
78+
input: './main.ts',
79+
plugins: [
80+
typescript({module: 'CommonJS'}),
81+
commonjs({extensions: ['.js', '.ts']}) // the ".ts" extension is required
82+
]
83+
}
5084
```
5185

86+
Note that this will often result in less optimal output.
87+
5288
## Issues
53-
Emit-less types, see [#28](https://github.com/rollup/rollup-plugin-typescript/issues/28).
89+
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.
90+
91+
This also causes issues with emit-less types, see [#28](https://github.com/rollup/rollup-plugin-typescript/issues/28).

0 commit comments

Comments
 (0)