0
# tsify
1
2
tsify is a Browserify plugin that compiles TypeScript files directly within the Browserify bundling process. It provides seamless integration between TypeScript's compiler and Browserify's module system, performing a single compilation pass of all TypeScript source files before bundling for optimal performance and complete type checking.
3
4
## Package Information
5
6
- **Package Name**: tsify
7
- **Package Type**: npm
8
- **Language**: JavaScript/TypeScript
9
- **Installation**: `npm install tsify`
10
11
## Core Imports
12
13
```javascript
14
const tsify = require('tsify');
15
```
16
17
For TypeScript projects with type definitions:
18
19
```typescript
20
import tsify = require('tsify');
21
```
22
23
## Basic Usage
24
25
### Browserify API
26
27
```javascript
28
const browserify = require('browserify');
29
const tsify = require('tsify');
30
31
browserify()
32
.add('main.ts')
33
.plugin(tsify, { noImplicitAny: true })
34
.bundle()
35
.on('error', function (error) { console.error(error.toString()); })
36
.pipe(process.stdout);
37
```
38
39
### Command Line
40
41
```bash
42
browserify main.ts -p [ tsify --noImplicitAny ] > bundle.js
43
```
44
45
### With tsconfig.json
46
47
tsify automatically detects and uses `tsconfig.json` files:
48
49
```javascript
50
browserify()
51
.add('src/main.ts')
52
.plugin(tsify) // Automatically uses tsconfig.json
53
.bundle()
54
.pipe(fs.createWriteStream('dist/bundle.js'));
55
```
56
57
## Architecture
58
59
tsify is built around several key components:
60
61
- **Plugin Interface**: Integrates with Browserify's plugin system to add TypeScript compilation
62
- **Tsifier**: Core compilation orchestrator that manages TypeScript compilation and caching
63
- **Host**: Virtual file system implementation that manages TypeScript source files in memory
64
- **Transform Stream**: Stream transformer that processes TypeScript files during bundling
65
- **Error Handling**: Comprehensive error reporting with TypeScript-specific diagnostics
66
67
## Capabilities
68
69
### Main Plugin Function
70
71
Core plugin interface for registering tsify with Browserify to enable TypeScript compilation.
72
73
```javascript { .api }
74
function tsify(browserifyInstance: any, options: TsifyOptions): void;
75
```
76
77
[Configuration](./configuration.md)
78
79
### TypeScript Compilation
80
81
Internal compilation engine that orchestrates TypeScript processing and manages file transformations.
82
83
```javascript { .api }
84
class Tsifier extends EventEmitter {
85
reset(): void;
86
generateCache(files: string[], ignoredFiles?: string[]): void;
87
compile(): void;
88
}
89
```
90
91
[Internal API](./internal-api.md)
92
93
### Error Handling
94
95
Comprehensive error reporting system for TypeScript compilation diagnostics with detailed location information.
96
97
```javascript { .api }
98
class CompileError extends SyntaxError {
99
fileName?: string;
100
line?: number;
101
column?: number;
102
}
103
```
104
105
[Error Handling](./error-handling.md)
106
107
### Build Tool Integration
108
109
Seamless integration with popular build tools and development workflows including watchify, Gulp, and Grunt.
110
111
```javascript { .api }
112
/** Integration with watchify for incremental compilation */
113
const watchify = require('watchify');
114
/** Integration with Gulp for build pipelines */
115
const gulp = require('gulp');
116
```
117
118
[Build Tool Integration](./integration.md)
119
120
## Types
121
122
```typescript { .api }
123
interface TsifyOptions {
124
/** Files/patterns to exclude from compilation */
125
exclude?: string[];
126
/** Explicit list of files to compile */
127
files?: string[];
128
/** Whether to set up as global transform */
129
global?: boolean;
130
/** Files/patterns to include in compilation */
131
include?: string[];
132
/** Short form for module option */
133
m?: string;
134
/** Short form for project option */
135
p?: string | Record<string, any>;
136
/** Path to tsconfig.json file or directory, or inline tsconfig object */
137
project?: string | Record<string, any>;
138
/** Short form for target option */
139
t?: string;
140
/** Custom TypeScript compiler reference */
141
typescript?: string | typeof import('typescript');
142
143
// All TypeScript compiler options are also supported
144
[key: string]: any;
145
}
146
```