You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 4, 2021. It is now read-only.
* 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
Note that both `typescript` and `tslib` are peer dependencies of this plugin that need to be installed separately.
19
+
18
20
## Usage
19
21
20
22
```js
@@ -23,31 +25,67 @@ import typescript from 'rollup-plugin-typescript';
23
25
24
26
exportdefault {
25
27
input:'./main.ts',
26
-
27
28
plugins: [
28
29
typescript()
29
30
]
30
31
}
31
32
```
32
33
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:
The following options are unique to `rollup-plugin-typescript`:
36
47
37
48
*`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).
38
49
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
+
```
40
58
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
+
```
42
65
43
66
### 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.
45
71
46
72
```js
47
-
typescript({
48
-
typescript:require('some-fork-of-typescript')
49
-
})
73
+
// rollup.config.js
74
+
importtypescriptfrom'rollup-plugin-typescript';
75
+
importcommonjsfrom'rollup-plugin-commonjs';
76
+
77
+
exportdefault {
78
+
input:'./main.ts',
79
+
plugins: [
80
+
typescript({module:'CommonJS'}),
81
+
commonjs({extensions: ['.js', '.ts']}) // the ".ts" extension is required
82
+
]
83
+
}
50
84
```
51
85
86
+
Note that this will often result in less optimal output.
87
+
52
88
## 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