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
Copy file name to clipboardExpand all lines: README.md
+14-9
Original file line number
Diff line number
Diff line change
@@ -14,11 +14,12 @@ This is the typescript loader for webpack.
14
14
15
15
### Examples
16
16
17
-
We have a number of example setups to accomodate different workflows. From "[vanilla](examples/vanilla)" ts-loader, to using ts-loader in combination with [babel](https://babeljs.io/) for transpilation, [happypack](https://github.com/amireh/happypack) or [thread-loader](https://github.com/webpack-contrib/thread-loader) for faster builds and [fork-ts-checker-webpack-plugin](https://github.com/Realytics/fork-ts-checker-webpack-plugin) for performing type checking in a separate process. Not forgetting [Hot Module Replacement](https://webpack.js.org/api/hot-module-replacement/). Our examples can be found [here](examples/).
17
+
We have a number of example setups to accomodate different workflows. Our examples can be found [here](examples/).
18
18
19
-
### Babel
19
+
We probably have more examples than we need. That said, here's a good way to get started:
20
20
21
-
ts-loader works very well in combination with [babel](https://babeljs.io/) and [babel-loader](https://github.com/babel/babel-loader). There is an [example](https://github.com/Microsoft/TypeScriptSamples/tree/master/react-flux-babel-karma) of this in the official [TypeScript Samples](https://github.com/Microsoft/TypeScriptSamples). Alternatively take a look at our own [example](examples/react-babel-karma-gulp).
21
+
- I want the simplest setup going. Use "[vanilla](examples/vanilla)" ts-loader
22
+
- I want the fastest compilation that's available. Use [fork-ts-checker-webpack-plugin](https://github.com/Realytics/fork-ts-checker-webpack-plugin). It performs type checking in a separate process with `ts-loader` just handling transpilation.
22
23
23
24
### Faster Builds
24
25
@@ -28,6 +29,10 @@ You probably don't want to give up type checking; that's rather the point of Typ
28
29
29
30
If you'd like to see a simple setup take a look at [our simple example](examples/fork-ts-checker/). For a more complex setup take a look at our [more involved example](examples/react-babel-karma-gulp).
30
31
32
+
### Babel
33
+
34
+
ts-loader works very well in combination with [babel](https://babeljs.io/) and [babel-loader](https://github.com/babel/babel-loader). There is an [example](https://github.com/Microsoft/TypeScriptSamples/tree/master/react-flux-babel-karma) of this in the official [TypeScript Samples](https://github.com/Microsoft/TypeScriptSamples). Alternatively take a look at our own [example](examples/react-babel-karma-gulp).
35
+
31
36
### Parallelising Builds
32
37
33
38
It's possible to parallelise your builds. Historically this was useful from a performance perspective with webpack 2 / 3. [With webpack 4+ there appears to be significantly less benefit and perhaps even cost.](https://blog.johnnyreilly.com/2018/12/you-might-not-need-thread-loader.html)
@@ -146,7 +151,7 @@ declare var require: {
146
151
147
152
Then you can simply require assets or chunks per the [webpack documentation](https://webpack.js.org/guides/code-splitting/).
148
153
149
-
```js
154
+
```javascript
150
155
require("!style!css!./style.css");
151
156
```
152
157
@@ -171,7 +176,7 @@ If you want to resolve modules according to `baseUrl` and `paths` in your `tscon
171
176
172
177
This feature requires webpack 2.1+ and TypeScript 2.0+. Use the config below or check the [package](https://github.com/dividab/tsconfig-paths-webpack-plugin/blob/master/README.md) for more information on usage.
@@ -244,7 +249,7 @@ If you're using [HappyPack](https://github.com/amireh/happypack) or [thread-load
244
249
245
250
It's advisable to use this with the [fork-ts-checker-webpack-plugin](https://github.com/Realytics/fork-ts-checker-webpack-plugin) to get full type checking again. To see what this looks like in practice then either take a look at [our simple HappyPack example](examples/happypack) / [our simple thread-loader example](examples/thread-loader). For a more complex setup take a look at our [more involved HappyPack example](examples/react-babel-karma-gulp-happypack) / [more involved thread-loader example](examples/react-babel-karma-gulp-thread-loader). **_IMPORTANT_**: If you are using fork-ts-checker-webpack-plugin alongside HappyPack or thread-loader then ensure you set the `checkSyntacticErrors` option like so:
@@ -326,7 +331,7 @@ By default ts-loader formats TypeScript compiler output for an error or a warnin
326
331
327
332
If that format is not to your taste you can supply your own formatter using the `errorFormatter` option. Below is a template for a custom error formatter. Please note that the `colors` parameter is an instance of [`chalk`](https://github.com/chalk/chalk) which you can use to color your output. (This instance will respect the `colors` option.)
@@ -339,7 +344,7 @@ function customErrorFormatter(error, colors) {
339
344
340
345
If the above formatter received an error like this:
341
346
342
-
```
347
+
```json
343
348
{
344
349
"code":2307,
345
350
"severity": "error",
@@ -588,7 +593,7 @@ Ok, so how is that relevant to ts-loader? Because the best way to think about wh
588
593
589
594
Because TS will generate .js and .d.ts files, you should ignore these files, otherwise watchers may go into an infinite watch loop. For example, when using webpack, you may wish to add this to your webpack.conf.js file:
0 commit comments