Skip to content

Commit

Permalink
Add fork-ts-checker-webpack-plugin info and examples (#540)
Browse files Browse the repository at this point in the history
* Add fork-ts-checker-webpack-plugin info and examples

* Self CR
  • Loading branch information
piotr-oles authored and johnnyreilly committed May 11, 2017
1 parent 71d0299 commit 9249f56
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Expand Up @@ -294,6 +294,19 @@ The same basic process is required for code splitting. In this case, you `import
don't directly use them. Instead you require them at [split points](http://webpack.github.io/docs/code-splitting.html#defining-a-split-point).
See [this example](test/comparison-tests/codeSplitting) and [this example](test/comparison-tests/es6codeSplitting) for more details.

### Faster incremental builds

As your project becomes bigger and bigger, compilation time increases linearly. It's because typescript's semantic checker has to inspect
all files on every rebuild.

The simple solution is to disable it by `transpileOnly: true` option but it leaves you without type checking.

If you don't want give up type checking, you can use [fork-ts-checker-webpack-plugin](https://github.com/Realytics/fork-ts-checker-webpack-plugin).
It runs checker on separate process, so your build is as fast as with `transpileOnly: true`. Also, it has several optimizations to make
incremental type checking faster (AST cache, multiple workers).

If you'd like to see a simple setup take a look at [our example](examples/webpack2-fork-ts-checker/).

## License

MIT License
14 changes: 14 additions & 0 deletions examples/webpack2-fork-ts-checker/package.json
@@ -0,0 +1,14 @@
{
"name": "webpack2-fork-ts-checker",
"main": "index.js",
"version": "1.0.0",
"scripts": {
"start": "./node_modules/.bin/webpack --watch"
},
"devDependencies": {
"fork-ts-checker-webpack-plugin": "^0.1.2",
"ts-loader": "^2.0.3",
"typescript": "^2.2.2",
"webpack": "^2.2.0"
}
}
4 changes: 4 additions & 0 deletions examples/webpack2-fork-ts-checker/src/fileWithError.ts
@@ -0,0 +1,4 @@

const x: number = '1';

export = x;
4 changes: 4 additions & 0 deletions examples/webpack2-fork-ts-checker/src/fileWithoutError.ts
@@ -0,0 +1,4 @@

const x: number = 1;

export = x;
5 changes: 5 additions & 0 deletions examples/webpack2-fork-ts-checker/src/index.ts
@@ -0,0 +1,5 @@

import * as x1 from './fileWithoutError';
import * as x2 from './fileWithError';

export = x1 + x2;
4 changes: 4 additions & 0 deletions examples/webpack2-fork-ts-checker/tsconfig.json
@@ -0,0 +1,4 @@
{
"compilerOptions": {
}
}
32 changes: 32 additions & 0 deletions examples/webpack2-fork-ts-checker/webpack.config.js
@@ -0,0 +1,32 @@
'use strict';

var process = require('process');
var ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');

module.exports = {
context: __dirname, // to automatically find tsconfig.json
entry: './src/index.ts',
output: { filename: 'index.js' },
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
options: {
transpileOnly: true // IMPORTANT! use transpileOnly mode to speed-up compilation
}
}
]
},
resolve: {
extensions: [ '.ts', '.tsx' ]
},
plugins: [
new ForkTsCheckerWebpackPlugin({
tslint: false, // disable tslint support
watch: './src', // optional but improves performance (less stat calls)
workers: ForkTsCheckerWebpackPlugin.TWO_CPUS_FREE, // use multi-process mode, leave 2 cpu's free for builder and system
blockEmit: process.env.NODE_ENV === 'production' // for production make it synchronous
})
]
};

0 comments on commit 9249f56

Please sign in to comment.