4
4
5
5
Webpack plugin that runs typescript type checker on a separate process.
6
6
7
- ## Installation ##
7
+ ## Installation
8
8
This plugin requires minimum ** webpack 2** , ** typescript 2.1** and optionally ** tslint 5.0**
9
9
``` sh
10
10
npm install --save-dev fork-ts-checker-webpack-plugin
@@ -41,52 +41,75 @@ var webpackConfig = {
41
41
};
42
42
```
43
43
44
- ## Motivation ##
44
+ ## Motivation
45
45
There is already similar solution - [ awesome-typescript-loader] ( https://github.com/s-panferov/awesome-typescript-loader ) . You can
46
46
add ` CheckerPlugin ` and delegate checker to the separate process. The problem with ` awesome-typescript-loader ` was that, in our case,
47
47
it was a lot slower than [ ts-loader] ( https://github.com/TypeStrong/ts-loader ) on an incremental build (~ 20s vs ~ 3s).
48
- Secondly, we use [ tslint] ( https://palantir.github.io/tslint/ ) and we wanted to run this, along with type checker, in a separate process.
48
+ Secondly, we use [ tslint] ( https://palantir.github.io/tslint ) and we wanted to run this, along with type checker, in a separate process.
49
49
This is why we've created this plugin. To provide better performance, plugin reuses Abstract Syntax Trees between compilations and shares
50
50
these trees with tslint. It can be scaled with a multi-process mode to utilize maximum CPU power.
51
51
52
- ## Options ##
53
- ** tsconfig** ` string ` - Path to tsconfig.json file. If not set, plugin will use ` path.resolve(compiler.options.context, './tsconfig.json') ` .
52
+ ## Modules resolution
53
+ It's very important to be aware that this plugin uses [ typescript] ( https://github.com/Microsoft/TypeScript ) 's, not
54
+ [ webpack] ( https://github.com/webpack/webpack ) 's modules resolution. It means that you have to setup ` tsconfig.json ` correctly. For example
55
+ if you set ` files: ['./src/someFile.ts'] ` in ` tsconfig.json ` , this plugin will check only ` someFile.ts ` for semantic errors. It's because
56
+ of performance. The goal of this plugin is to be as fast as possible. With typescript's module resolution we don't have to wait for webpack
57
+ to compile files (which traverses dependency graph during compilation) - we have a full list of files from the begin.
54
58
55
- ** tslint** ` string | false ` - Path to tslint.json file. If not set, plugin will use ` path.resolve(compiler.options.context, './tslint.json') ` .
56
- If ` false ` , disables tslint.
59
+ To debug typescript's modules resolution, you can use ` tsc --traceResolution ` command.
57
60
58
- ** watch** ` string | string[] ` - Directories or files to watch by service. Not necessary but improves performance
59
- (reduces number of ` fs.stat ` calls).
61
+ ## TSLint
62
+ If you have installed [ tslint] ( https://palantir.github.io/tslint ) , it's enabled by default. To disable it, set ` tslint: false ` in plugin
63
+ options. We recommend changing ` defaultSeverity ` to the ` warning ` in ` tslint.json ` file. It helps to distinguish lints from typescript's
64
+ diagnostics.
65
+
66
+ ## Options
67
+ #### tsconfig ` string `
68
+ Path to tsconfig.json file. Default: ` path.resolve(compiler.options.context, './tsconfig.json') `
69
+
70
+ #### tslint ` string | false `
71
+ Path to tslint.json file. If ` false ` , disables tslint. Default: ` path.resolve(compiler.options.context, './tslint.json') `
72
+
73
+ #### watch ` string | string[] `
74
+ Directories or files to watch by service. Not necessary but improves performance (reduces number of ` fs.stat ` calls).
60
75
61
- ** blockEmit** ` boolean ` - If ` true ` , plugin will block emit until check will be done. It's good setting for ci/production build because
62
- webpack will return code != 0 if there are type/lint errors. Default: ` false ` .
76
+ #### blockEmit ` boolean `
77
+ If ` true ` , plugin will block emit until check will be done. It's good setting for ci/production build because webpack will return code != 0
78
+ if there are type/lint errors. Default: ` false ` .
79
+
80
+ #### ignoreDiagnostics ` number[] `
81
+ List of typescript diagnostic codes to ignore.
63
82
64
- ** ignoreDiagnostics** ` number[] ` - List of typescript diagnostic codes to ignore.
83
+ #### ignoreLints ` string[] `
84
+ List of tslint rule names to ignore.
65
85
66
- ** ignoreLints** ` string[] ` - List of tslint rule names to ignore.
86
+ #### colors ` boolean `
87
+ If ` false ` , disables built-in colors in logger messages. Default: ` true ` .
67
88
68
- ** colors** ` boolean ` - If ` false ` , disables built-in colors in logger messages. Default: ` true ` .
89
+ #### logger ` object `
90
+ Logger instance. It should be object that implements method: ` error ` , ` warn ` , ` info ` . Default: ` console ` .
69
91
70
- ** logger** ` object ` - Logger instance. It should be object that implements method: ` error ` , ` warn ` , ` info ` . Default: ` console ` .
92
+ #### silent ` boolean `
93
+ If ` true ` , logger will not be used. Default: ` false ` .
71
94
72
- ** silent** ` boolean ` - If ` true ` , logger will not be used. Default: ` false ` .
95
+ #### workers ` number `
96
+ You can split type checking to a few workers to speed-up increment build. ** Be careful** - if you don't want to increase build time, you
97
+ should keep free 1 core for * build* and 1 core for a * system* * (for example system with 4 CPUs should use max 2 workers)* . Second thing -
98
+ node doesn't share memory between workers - keep in mind that memory usage will increase. Be aware that in some scenarios increasing workers
99
+ number ** can increase checking time** .
73
100
74
- ** workers** ` number ` - You can split type checking to a few workers to speed-up increment build.
75
- ** Be careful** - if you don't want to increase build time, you should keep free 1 core for * build* and 1 core for
76
- a * system* * (for example system with 4 CPUs should use max 2 workers)* .
77
- Second thing - node doesn't share memory between workers - keep in mind that memory usage will increase.
78
- Be aware that in some scenarios increasing workers number ** can increase checking time** .
79
- Default: ` ForkTsCheckerWebpackPlugin.ONE_CPU ` .
101
+ Default: ` ForkTsCheckerWebpackPlugin.ONE_CPU ` .
80
102
81
103
Pre-computed consts:
82
104
* ` ForkTsCheckerWebpackPlugin.ONE_CPU ` - always use one CPU
105
+ * ` ForkTsCheckerWebpackPlugin.ALL_CPUS ` - always use all CPUs (will increase build time)
83
106
* ` ForkTsCheckerWebpackPlugin.ONE_CPU_FREE ` - leave only one CPU for build (probably will increase build time)
84
- * ` ForkTsCheckerWebpackPlugin.TWO_CPUS_FREE ` - leave two CPUs free (one for build, one for system)
107
+ * ` ForkTsCheckerWebpackPlugin.TWO_CPUS_FREE ` - ** recommended ** - leave two CPUs free (one for build, one for system)
85
108
86
- ** memoryLimit** ` number ` - Memory limit for service process in MB. If service exits with allocation failed error, increase this number.
87
- Default: ` 2048 ` .
109
+ #### memoryLimit ` number `
110
+ Memory limit for service process in MB. If service exits with allocation failed error, increase this number. Default: ` 2048 ` .
88
111
89
- ## Plugin Hooks ##
112
+ ## Plugin Hooks
90
113
This plugin provides some custom webpack hooks (all are sync):
91
114
92
115
| Event name | Description | Params |
@@ -100,5 +123,5 @@ This plugin provides some custom webpack hooks (all are sync):
100
123
| ` fork-ts-checker-emit ` | Service will add errors and warnings to webpack compilation (` blockEmit: true ` ) | ` diagnostics ` , ` lints ` , ` elapsed ` |
101
124
| ` fork-ts-checker-done ` | Service finished type checking and webpack finished compilation (` blockEmit: false ` ) | ` diagnostics ` , ` lints ` , ` elapsed ` |
102
125
103
- ## License ##
126
+ ## License
104
127
MIT
0 commit comments