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
-`watch` - Use `gulp.watch` instead. See the paragraph "Incremental compilation".
58
61
-`project` - See "Using `tsconfig.json`".
59
62
- Obvious: `help`, `version`
60
63
61
-
## Unofficial options
62
-
Besides the official options options, gulp-typescript supports the following options:
63
-
-```noExternalResolve``` (boolean) - Do not resolve files that are not in the input. Explanation below.
64
-
-```sortOutput``` (boolean) - Sort output files. Useful if you want to concatenate files (see below).
65
-
-```typescript``` (object) - Use a different version / fork of TypeScript (see below). Use it like: `typescript: require('typescript')` or `typescript: require('my-fork-of-typescript')`
66
-
67
64
Basic Usage
68
65
----------
69
66
Below is a minimal `gulpfile.js` which will compile all TypeScript file in folder `src` and emit a single output file called `output.js` in `built/local`. To invoke, simple run `gulp`.
@@ -81,17 +78,16 @@ gulp.task('default', function () {
81
78
.pipe(gulp.dest('built/local'));
82
79
});
83
80
```
84
-
Another example of `gulpfile.js`. Instead of creating default task, the file specifies custom named task. To invoke, run `gulp scripts` instead of `gulp`. As a result, the task will generate both JavaScript files and TypeScript definition files (.d.ts).
81
+
Another example of `gulpfile.js`. Instead of creating the default task, the file specifies custom named task. To invoke, run `gulp scripts` instead of `gulp`. As a result, the task will generate both JavaScript files and TypeScript definition files (`.d.ts`).
85
82
```javascript
86
83
var gulp =require('gulp');
87
84
var ts =require('gulp-typescript');
88
-
var merge =require('merge2'); //Require separate installation
85
+
var merge =require('merge2'); //Requires separate installation
When you run ```gulp watch```, the source will be compiled as usual. Then, when you make a change and save the file, your TypeScript files will be compiled in about half the time.
131
+
When you run `gulp watch`, the source will be compiled as usual. Then, when you make a change and save the file, your TypeScript files will be compiled in about half the time.
135
132
136
133
You must create the project outside of the task. You can't use the same project in multiple tasks.
137
134
Instead, create multiple projects or use a single task to compile your sources.
@@ -144,93 +141,35 @@ var tsProject = ts.createProject('tsconfig.json');
144
141
```
145
142
If you want to add or overwrite certain settings in the `tsconfig.json` file, you can use:
146
143
```javascript
147
-
var tsProject =ts.createProject('tsconfig.json', { sortOutput:true });
144
+
var tsProject =ts.createProject('tsconfig.json', { noImplicitAny:true });
148
145
```
149
146
The task will look like:
150
147
```javascript
151
148
gulp.task('scripts', function() {
152
149
var tsResult =tsProject.src() // instead of gulp.src(...)
153
-
.pipe(ts(tsProject));
150
+
.pipe(tsProject());
154
151
155
152
returntsResult.js.pipe(gulp.dest('release'));
156
153
});
157
154
```
158
155
159
156
TypeScript version
160
157
------------------
161
-
gulp-typescript uses TypeScript 1.8 by default. You can also use 1.4+ or a nighty version of TypeScript instead.
162
-
You should add the version you want (1.4+) to your package.json file as a devDependency. You can use the a nightly build to get the latest features:
163
-
```
164
-
npm install typescript@next
165
-
```
166
-
And add this to your gulpfile:
167
-
```javascript
168
-
[...].pipe(ts({
169
-
typescript:require('typescript')
170
-
}));
171
-
```
172
-
Or in combination with a `tsconfig` file:
173
-
```javascript
174
-
var tsProject =ts.createProject('tsconfig.json', {
175
-
typescript:require('typescript')
176
-
});
177
-
```
158
+
gulp-typescript isn't restricted to a single TypeScript version.
159
+
You can install the latest stable version using `npm install typescript --save-dev` or a nightly `npm install typescript@next --save-dev`.
178
160
179
-
It's also possible to use a fork of TypeScript. Add an extra option to the options object like this:
161
+
You can also use a fork of TypeScript, if it is based on TypeScript 2.x. You can configure this in your gulpfile:
var tsProject =ts.createProject('tsconfig.json', {
170
+
typescript:require('my-form-of-typescript')
204
171
});
205
172
```
206
-
The first example doesn't add files (that don't pass the filter) to the compiler, the second one does add them to the compiler,
207
-
but removes them later from the stream.
208
-
You can put as much pipes between compilation and filtering as you want, as long as the filename doesn't change.
209
-
210
-
At the moment there is only one filter available:
211
-
212
-
-```referencedFrom``` (string[]) Only files that are referenced (using ```/// <reference path="..." />```) by the files in this array pass this filter.
213
-
214
-
Resolving files
215
-
---------------
216
-
By default, gulp-typescript will try to resolve the files you require and reference. These files are parsed, but not emitted (so you will not see them in the output stream).
217
-
218
-
If you set the option ```noExternalResolve``` to true, gulp-typescript will not resolve all the requires and references. It assumes that all the necessary files are in the input stream. For example, if you have your ```.ts``` files in the ```lib``` folder, and the ```.d.ts``` files in the ```definitions``` folder, you must use ```gulp.src(['lib/**.ts', 'definitions/**.ts'])``` instead of ```gulp.src(['lib/**.ts'])``` in your gulpfile if you use the option ```noExternalResolve```.
219
-
220
-
Advantage of ```noExternalResolve```: faster compilation.
221
-
Disadvantage of ```noExternalResolve```: won't work when you forgot some input files.
222
-
Advice: turn it on, and make sure you list all the input files.
223
-
224
-
Files that are resolved when ```noExternalResolve``` is off, won't be pushed to the output stream, unless you are using the `out` option.
225
-
226
-
Concatenate files
227
-
------------
228
-
The ```tsc``` command has the ability to concatenate using the ```--out``` parameter. There are two approaches to do that in ```gulp-typescript```.
229
-
230
-
You can use the `out` option. This is fine for small projects, but for big projects it's not always sufficient.
231
-
232
-
The other option is to use `gulp-concat`. The ```tsc``` command sorts the files using the ```<reference>``` tags. ```gulp-typescript``` does this when you enable the ```sortOutput``` option. You can use the ```referencedFrom``` filter to only include files that are referenced from certain files.
233
-
234
173
235
174
Source maps
236
175
----------
@@ -240,19 +179,17 @@ associated sourcemap.
240
179
```javascript
241
180
var gulp =require('gulp')
242
181
var ts =require('gulp-typescript');
243
-
var concat =require('gulp-concat');
244
182
var sourcemaps =require('gulp-sourcemaps');
245
183
246
184
gulp.task('scripts', function() {
247
185
var tsResult =gulp.src('lib/*.ts')
248
186
.pipe(sourcemaps.init()) // This means sourcemaps will be generated
249
187
.pipe(ts({
250
-
sortOutput:true,
251
188
// ...
252
189
}));
253
190
254
191
returntsResult.js
255
-
.pipe(concat('output.js')) // You can use other plugins that also support gulp-sourcemaps
192
+
.pipe(...) // You can use other plugins that also support gulp-sourcemaps
256
193
.pipe(sourcemaps.write()) // Now the sourcemaps are added to the .js file
257
194
.pipe(gulp.dest('release/js'));
258
195
});
@@ -261,17 +198,18 @@ For more information, see [gulp-sourcemaps](https://github.com/floridoo/gulp-sou
261
198
262
199
Reporters
263
200
---------
264
-
You can specify a custom reporter as the 3rd argument of the main function:
201
+
You can specify a custom reporter as the second argument of the main function, or as the only argument when using a `tsProject`:
265
202
```javascript
266
-
ts(optionsOrProject, filters, reporter);
203
+
ts(options, reporter);
204
+
tsProject(reporter);
267
205
```
268
-
You can set options, project or filter to `undefined` if you don't want to set them. Available reporters are:
- defaultReporter (`ts.reporter.defaultReporter()`) - Report basic errors to the console
271
209
- longReporter (`ts.reporter.longReporter()`) - Extended version of default reporter, intelliJ link functionality + file watcher error highlighting should work using this one
272
210
- fullReporter (`ts.reporter.fullReporter(showFullFilename?: boolean)`) - Show full error messages, with source.
273
211
274
-
If you want to build a custom reporter, you take a look at `lib/reporter.ts`, in that file is an interface which a reporter should implement.
212
+
If you want to build a custom reporter, you take a look at `lib/reporter.ts`, that file declares an interface which a reporter should implement.
0 commit comments