UNPKG

27.1 kBMarkdownView Raw
1# TypeScript loader for webpack
2
3[![npm Version](https://img.shields.io/npm/v/ts-loader.svg)](https://www.npmjs.com/package/ts-loader)
4[![Build Status](https://travis-ci.org/TypeStrong/ts-loader.svg?branch=master)](https://travis-ci.org/TypeStrong/ts-loader)
5[![Build Status](https://ci.appveyor.com/api/projects/status/bjh0r0d4ckspgkh9/branch/master?svg=true)](https://ci.appveyor.com/project/JohnReilly/ts-loader/branch/master)
6[![Downloads](http://img.shields.io/npm/dm/ts-loader.svg)](https://npmjs.org/package/ts-loader)
7[![Greenkeeper badge](https://badges.greenkeeper.io/TypeStrong/ts-loader.svg)](https://greenkeeper.io/)
8[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
9[![Join the chat at https://gitter.im/TypeStrong/ts-loader](https://img.shields.io/badge/gitter-join%20chat-brightgreen.svg)](https://gitter.im/TypeStrong/ts-loader)
10
11This is the typescript loader for webpack.
12
13## Getting Started
14
15### Examples
16
17We 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/).
18
19### Babel
20
21ts-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).
22
23### Faster Builds
24
25As your project becomes 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 using the `transpileOnly: true` option, but doing so leaves you without type checking and *will not output declaration files*.
26
27You probably don't want to give up type checking; that's rather the point of TypeScript. So what you can do is use the [fork-ts-checker-webpack-plugin](https://github.com/Realytics/fork-ts-checker-webpack-plugin). It runs the type checker on a separate process, so your build remains fast thanks to `transpileOnly: true` but you still have the type checking. Also, the plugin has several optimizations to make incremental type checking faster (AST cache, multiple workers).
28
29If 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-fork-ts-checker).
30
31If you'd like to make things even faster still (I know, right?) then you might want to consider using ts-loader with [happypack](https://github.com/amireh/happypack) which speeds builds by parallelising work. (This should be used in combination with [fork-ts-checker-webpack-plugin](https://github.com/Realytics/fork-ts-checker-webpack-plugin) for typechecking.) If you'd like to see a simple setup take a look at [our simple example](examples/happypack/). For a more complex setup take a look at our [more involved example](examples/react-babel-karma-gulp-happypack).
32
33There is a "webpack-way" of parallelising builds. Instead of using happypack you can use ts-loader with ts-loader with [thread-loader](https://github.com/webpack-contrib/thread-loader) and [cache-loader](https://github.com/webpack-contrib/cache-loader) in combination. (Again, this should be used in combination with [fork-ts-checker-webpack-plugin](https://github.com/Realytics/fork-ts-checker-webpack-plugin) for typechecking.) If you'd like to see a simple setup take a look at [our simple example](examples/thread-loader/). For a more complex setup take a look at our [more involved example](examples/react-babel-karma-gulp-thread-loader).
34
35To read more, look at [this post](https://medium.com/webpack/typescript-webpack-super-pursuit-mode-83cc568dea79) by [@johnny_reilly](https://twitter.com/johnny_reilly) on the webpack publication channel.
36
37If you'd like find out further ways to improve your build using the watch API then take a look at [this post](https://medium.com/@kenneth_chau/speeding-up-webpack-typescript-incremental-builds-by-7x-3912ba4c1d15) by [@kenneth_chau](https://twitter.com/kenneth_chau). To see an example setup that Ken generously contributed take a look [here](examples/fast-incremental-builds).
38
39### Installation
40
41```
42yarn add ts-loader
43```
44
45or
46
47```
48npm install ts-loader
49```
50
51You will also need to install TypeScript if you have not already.
52
53```
54yarn add typescript
55```
56
57or
58
59```
60npm install typescript
61```
62
63### Running
64
65Use webpack like normal, including `webpack --watch` and `webpack-dev-server`, or through another
66build system using the [Node.js API](http://webpack.github.io/docs/node.js-api.html).
67
68### Compatibility
69
70* TypeScript: 2.4.1+
71* webpack: 4.x+ (please use ts-loader 3.x if you need webpack 2 or 3 support)
72* node: 6.11.5 minimum (aligned with webpack 4)
73
74A full test suite runs each night (and on each pull request). It runs both on [Linux](https://travis-ci.org/TypeStrong/ts-loader) and [Windows](https://ci.appveyor.com/project/JohnReilly/ts-loader), testing ts-loader against major releases of TypeScript. The test suite also runs against TypeScript@next (because we want to use it as much as you do).
75
76If you become aware of issues not caught by the test suite then please let us know. Better yet, write a test and submit it in a PR!
77
78### Configuration
79
801. Create or update `webpack.config.js` like so:
81
82 ```javascript
83 module.exports = {
84 mode: "development",
85 devtool: "inline-source-map",
86 entry: "./app.ts",
87 output: {
88 filename: "bundle.js"
89 },
90 resolve: {
91 // Add `.ts` and `.tsx` as a resolvable extension.
92 extensions: [".ts", ".tsx", ".js"]
93 },
94 module: {
95 rules: [
96 // all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
97 { test: /\.tsx?$/, loader: "ts-loader" }
98 ]
99 }
100 };
101 ```
102
1032. Add a [`tsconfig.json`](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) file. (The one below is super simple; but you can tweak this to your hearts desire)
104
105 ```json
106 {
107 "compilerOptions": {
108 "sourceMap": true
109 }
110 }
111 ```
112
113The [tsconfig.json](http://www.typescriptlang.org/docs/handbook/tsconfig-json.html) file controls
114TypeScript-related options so that your IDE, the `tsc` command, and this loader all share the
115same options.
116
117#### `devtool` / sourcemaps
118
119If you want to be able to debug your original source then you can thanks to the magic of sourcemaps. There are 2 steps to getting this set up with ts-loader and webpack.
120
121First, for ts-loader to produce **sourcemaps**, you will need to set the [tsconfig.json](http://www.typescriptlang.org/docs/handbook/tsconfig-json.html) option as `"sourceMap": true`.
122
123Second, you need to set the `devtool` option in your `webpack.config.js` to support the type of sourcemaps you want. To make your choice have a read of the [`devtool` webpack docs](https://webpack.js.org/configuration/devtool/). You may be somewhat daunted by the choice available. You may also want to vary the sourcemap strategy depending on your build environment. Here are some example strategies for different environments:
124
125* `devtool: 'inline-source-map'` - Solid sourcemap support; the best "all-rounder". Works well with karma-webpack (not all strategies do)
126* `devtool: 'cheap-module-eval-source-map'` - Best support for sourcemaps whilst debugging.
127* `devtool: 'source-map'` - Approach that plays well with UglifyJsPlugin; typically you might use this in Production
128
129### Code Splitting and Loading Other Resources
130
131Loading css and other resources is possible but you will need to make sure that
132you have defined the `require` function in a [declaration file](https://www.typescriptlang.org/docs/handbook/writing-declaration-files.html).
133
134```typescript
135declare var require: {
136 <T>(path: string): T;
137 (paths: string[], callback: (...modules: any[]) => void): void;
138 ensure: (
139 paths: string[],
140 callback: (require: <T>(path: string) => T) => void
141 ) => void;
142};
143```
144
145Then you can simply require assets or chunks per the [webpack documentation](https://webpack.js.org/guides/code-splitting/).
146
147```js
148require("!style!css!./style.css");
149```
150
151The same basic process is required for code splitting. In this case, you `import` modules you need but you
152don'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.
153
154[TypeScript 2.4 provides support for ECMAScript's new `import()` calls. These calls import a module and return a promise to that module.](https://blogs.msdn.microsoft.com/typescript/2017/06/12/announcing-typescript-2-4-rc/) This is also supported in webpack - details on usage can be found [here](https://webpack.js.org/guides/code-splitting-async/#dynamic-import-import-). Happy code splitting!
155
156### Declarations (.d.ts)
157
158To output a built .d.ts file, you can set "declaration": true in your tsconfig, and use the [DeclarationBundlerPlugin](https://www.npmjs.com/package/declaration-bundler-webpack-plugin) in your webpack config.
159
160### Failing the build on TypeScript compilation error
161
162The build **should** fail on TypeScript compilation errors as of webpack 2. If for some reason it does not, you can use the [webpack-fail-plugin](https://www.npmjs.com/package/webpack-fail-plugin).
163
164For more background have a read of [this issue](https://github.com/TypeStrong/ts-loader/issues/108).
165
166### `baseUrl` / `paths` module resolution
167
168If you want to resolve modules according to `baseUrl` and `paths` in your `tsconfig.json` then you can use the [tsconfig-paths-webpack-plugin](https://www.npmjs.com/package/tsconfig-paths-webpack-plugin) package. For details about this functionality, see the [module resolution documentation](https://www.typescriptlang.org/docs/handbook/module-resolution.html#base-url).
169
170This 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.
171
172```js
173const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
174
175module.exports = {
176 ...
177 resolve: {
178 plugins: [new TsconfigPathsPlugin({ /*configFile: "./path/to/tsconfig.json" */ })]
179 }
180 ...
181}
182```
183
184### Options
185
186There are two types of options: TypeScript options (aka "compiler options") and loader options. TypeScript options should be set using a tsconfig.json file. Loader options can be specified through the `options` property in the webpack configuration:
187
188```javascript
189module.exports = {
190 ...
191 module: {
192 rules: [
193 {
194 test: /\.tsx?$/,
195 use: [
196 {
197 loader: 'ts-loader',
198 options: {
199 transpileOnly: true
200 }
201 }
202 ]
203 }
204 ]
205 }
206}
207```
208
209### Loader Options
210
211#### transpileOnly _(boolean) (default=false)_
212
213If you want to speed up compilation significantly you can set this flag.
214However, many of the benefits you get from static type checking between
215different dependencies in your application will be lost.
216
217It's advisable to use `transpileOnly` alongside 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 example](examples/fork-ts-checker). For a more complex setup take a look at our [more involved example](examples/react-babel-karma-gulp-fork-ts-checker).
218
219If you enable this option, webpack 4 will give you "export not found" warnings any time you re-export a type:
220
221```
222WARNING in ./src/bar.ts
2231:0-34 "export 'IFoo' was not found in './foo'
224 @ ./src/bar.ts
225 @ ./src/index.ts
226```
227
228The reason this happens is that when typescript doesn't do a full type check, it does not have enough information to determine whether an imported name is a type or not, so when the name is then exported, typescript has no choice but to emit the export. Fortunately, the extraneous export should not be harmful, so you can just suppress these warnings:
229
230```javascript
231module.exports = {
232 ...
233 stats: {
234 warningsFilter: /export .* was not found in/
235 }
236}
237```
238
239#### happyPackMode _(boolean) (default=false)_
240
241If you're using [HappyPack](https://github.com/amireh/happypack) or [thread-loader](https://github.com/webpack-contrib/thread-loader) to parallise your builds then you'll need to set this to `true`. This implicitly sets `*transpileOnly*` to `true` and **WARNING!** stops registering **_all_** errors to webpack.
242
243It'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:
244
245```
246 new ForkTsCheckerWebpackPlugin({ checkSyntacticErrors: true })
247```
248
249This will ensure that the plugin checks for both syntactic errors (eg `const array = [{} {}];`) and semantic errors (eg `const x: number = '1';`). By default the plugin only checks for semantic errors (as when used with ts-loader in `transpileOnly` mode, ts-loader will still report syntactic errors).
250
251#### getCustomTransformers _( () => { before?: TransformerFactory<SourceFile>[]; after?: TransformerFactory<SourceFile>[]; } )_
252
253Provide custom transformers - only compatible with TypeScript 2.3+ (and 2.4 if using `transpileOnly` mode). For example usage take a look at [typescript-plugin-styled-components](https://github.com/Igorbek/typescript-plugin-styled-components) or our [test](test/comparison-tests/customTransformer).
254
255You can also pass a path string to locate a js module file which exports the function described above, this useful especially in `happyPackMode`. (Because forked proccess cannot serialize functions see more at [related issue](https://github.com/Igorbek/typescript-plugin-styled-components/issues/6#issue-303387183))
256
257#### logInfoToStdOut _(boolean) (default=false)_
258
259This is important if you read from stdout or stderr and for proper error handling.
260The default value ensures that you can read from stdout e.g. via pipes or you use webpack -j to generate json output.
261
262#### logLevel _(string) (default=warn)_
263
264Can be `info`, `warn` or `error` which limits the log output to the specified log level.
265Beware of the fact that errors are written to stderr and everything else is written to stderr (or stdout if logInfoToStdOut is true).
266
267#### silent _(boolean) (default=false)_
268
269If true, no console.log messages will be emitted. Note that most error
270messages are emitted via webpack which is not affected by this flag.
271
272#### ignoreDiagnostics _(number[]) (default=[])_
273
274You can squelch certain TypeScript errors by specifying an array of diagnostic
275codes to ignore.
276
277#### reportFiles _(string[]) (default=[])_
278
279Only report errors on files matching these glob patterns.
280
281```javascript
282 // in webpack.config.js
283 {
284 test: /\.ts$/,
285 loader: 'ts-loader',
286 options: { reportFiles: ['src/**/*.{ts,tsx}', '!src/skip.ts'] }
287 }
288```
289
290This can be useful when certain types definitions have errors that are not fatal to your application.
291
292#### compiler _(string) (default='typescript')_
293
294Allows use of TypeScript compilers other than the official one. Should be
295set to the NPM name of the compiler, eg [`ntypescript`](https://github.com/basarat/ntypescript).
296
297#### configFile _(string) (default='tsconfig.json')_
298
299Allows you to specify where to find the TypeScript configuration file.
300
301You may provide
302
303* just a file name. The loader then will search for the config file of each entry point in the respective entry point's containing folder. If a config file cannot be found there, it will travel up the parent directory chain and look for the config file in those folders.
304* a relative path to the configuration file. It will be resolved relative to the respective `.ts` entry file.
305* an absolute path to the configuration file.
306
307Please note, that if the configuration file is outside of your project directory, you might need to set the `context` option to avoid TypeScript issues (like TS18003).
308In this case the `configFile` should point to the `tsconfig.json` and `context` to the project root.
309
310#### colors _(boolean) (default=true)_
311
312If `false`, disables built-in colors in logger messages.
313
314#### errorFormatter _((message: ErrorInfo, colors: boolean) => string) (default=undefined)_
315
316By default ts-loader formats TypeScript compiler output for an error or a warning in the style:
317
318```
319[tsl] ERROR in myFile.ts(3,14)
320 TS4711: you did something very wrong
321```
322
323If 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.)
324
325```js
326function customErrorFormatter(error, colors) {
327 const messageColor =
328 error.severity === "warning" ? colors.bold.yellow : colors.bold.red;
329 return (
330 "Does not compute.... " +
331 messageColor(Object.keys(error).map(key => `${key}: ${error[key]}`))
332 );
333}
334```
335
336If the above formatter received an error like this:
337
338```
339{
340 "code":2307,
341 "severity": "error",
342 "content": "Cannot find module 'components/myComponent2'.",
343 "file":"/.test/errorFormatter/app.ts",
344 "line":2,
345 "character":31
346}
347```
348
349It would produce an error message that said:
350
351```
352Does not compute.... code: 2307,severity: error,content: Cannot find module 'components/myComponent2'.,file: /.test/errorFormatter/app.ts,line: 2,character: 31
353```
354
355And the bit after "Does not compute.... " would be red.
356
357#### compilerOptions _(object) (default={})_
358
359Allows overriding TypeScript options. Should be specified in the same format
360as you would do for the `compilerOptions` property in tsconfig.json.
361
362#### instance _(string)_
363
364Advanced option to force files to go through different instances of the
365TypeScript compiler. Can be used to force segregation between different parts
366of your code.
367
368#### appendTsSuffixTo _(RegExp[]) (default=[])_
369
370#### appendTsxSuffixTo _(RegExp[]) (default=[])_
371
372A list of regular expressions to be matched against filename. If filename matches one of the regular expressions, a `.ts` or `.tsx` suffix will be appended to that filename.
373
374This is useful for `*.vue` [file format](https://vuejs.org/v2/guide/single-file-components.html) for now. (Probably will benefit from the new single file format in the future.)
375
376Example:
377
378webpack.config.js:
379
380```javascript
381module.exports = {
382 entry: "./index.vue",
383 output: { filename: "bundle.js" },
384 resolve: {
385 extensions: [".ts", ".vue"]
386 },
387 module: {
388 rules: [
389 { test: /\.vue$/, loader: "vue-loader" },
390 {
391 test: /\.ts$/,
392 loader: "ts-loader",
393 options: { appendTsSuffixTo: [/\.vue$/] }
394 }
395 ]
396 }
397};
398```
399
400index.vue
401
402```vue
403<template><p>hello {{msg}}</p></template>
404<script lang="ts">
405export default {
406 data(): Object {
407 return {
408 msg: "world"
409 };
410 }
411};
412</script>
413```
414
415We can handle `.tsx` by quite similar way:
416
417webpack.config.js:
418
419```javascript
420module.exports = {
421 entry: './index.vue',
422 output: { filename: 'bundle.js' },
423 resolve: {
424 extensions: ['.ts', '.tsx', '.vue', '.vuex']
425 },
426 module: {
427 rules: [
428 { test: /\.vue$/, loader: 'vue-loader',
429 options: {
430 loaders: {
431 ts: 'ts-loader',
432 tsx: 'babel-loader!ts-loader',
433 }
434 }
435 },
436 { test: /\.ts$/, loader: 'ts-loader', options: { appendTsSuffixTo: [/TS\.vue$/] } }
437 { test: /\.tsx$/, loader: 'babel-loader!ts-loader', options: { appendTsxSuffixTo: [/TSX\.vue$/] } }
438 ]
439 }
440}
441```
442
443tsconfig.json (set `jsx` option to `preserve` to let babel handle jsx)
444
445```json
446{
447 "compilerOptions": {
448 "jsx": "preserve"
449 }
450}
451```
452
453index.vue
454
455```vue
456<script lang="tsx">
457export default {
458 functional: true,
459 render(h, c) {
460 return (<div>Content</div>);
461 }
462}
463</script>
464```
465
466Or if you want to use only tsx, just use the `appendTsxSuffixTo` option only:
467
468```javascript
469 { test: /\.ts$/, loader: 'ts-loader' }
470 { test: /\.tsx$/, loader: 'babel-loader!ts-loader', options: { appendTsxSuffixTo: [/\.vue$/] } }
471```
472
473#### onlyCompileBundledFiles _(boolean) (default=false)_
474
475The default behavior of ts-loader is to act as a drop-in replacement for the `tsc` command,
476so it respects the `include`, `files`, and `exclude` options in your `tsconfig.json`, loading
477any files specified by those options. The `onlyCompileBundledFiles` option modifies this behavior,
478loading only those files that are actually bundled by webpack, as well as any `.d.ts` files included
479by the `tsconfig.json` settings. `.d.ts` files are still included because they may be needed for
480compilation without being explicitly imported, and therefore not picked up by webpack.
481
482#### allowTsInNodeModules _(boolean) (default=false)_
483
484By default, ts-loader will not compile `.ts` files in `node_modules`.
485You should not need to recompile `.ts` files there, but if you really want to, use this option.
486Note that this option acts as a *whitelist* - any modules you desire to import must be included in
487the `"files"` or `"include"` block of your project's `tsconfig.json`.
488
489See: [https://github.com/Microsoft/TypeScript/issues/12358](https://github.com/Microsoft/TypeScript/issues/12358)
490
491```javascript
492 // in webpack.config.js
493 {
494 test: /\.ts$/,
495 loader: 'ts-loader',
496 options: { allowTsInNodeModules: true }
497 }
498```
499
500And in your `tsconfig.json`:
501
502```json
503 {
504 "include": [
505 "node_modules/whitelisted_module.ts"
506 ],
507 "files": [
508 "node_modules/my_module/whitelisted_file.ts"
509 ]
510 }
511```
512
513#### context _(string) (default=undefined)_
514
515If set, will parse the TypeScript configuration file with given **absolute path** as base path.
516Per default the directory of the configuration file is used as base path. Relative paths in the configuration
517file are resolved with respect to the base path when parsed. Option `context` allows to set option
518`configFile` to a path other than the project root (e.g. a NPM package), while the base path for `ts-loader`
519can remain the project root.
520
521Keep in mind that **not** having a `tsconfig.json` in your project root can cause different behaviour between `ts-loader` and `tsc`.
522When using editors like `VS Code` it is advised to add a `tsconfig.json` file to the root of the project and extend the config file
523referenced in option `configFile`. For more information please [read the PR](https://github.com/TypeStrong/ts-loader/pull/681) that
524is the base and [read the PR](https://github.com/TypeStrong/ts-loader/pull/688) that contributed this option.
525
526Webpack:
527
528```javascript
529{
530 loader: require.resolve('ts-loader'),
531 options: {
532 context: __dirname,
533 configFile: require.resolve('ts-config-react-app')
534 }
535}
536```
537
538Extending `tsconfig.json`:
539
540```json
541{ "extends": "./node_modules/ts-config-react-app/index" }
542```
543
544Note that changes in the extending file while not be respected by `ts-loader`. Its purpose is to satisfy the code editor.
545
546### `LoaderOptionsPlugin`
547
548[There's a known "gotcha"](https://github.com/TypeStrong/ts-loader/issues/283) if you are using webpack 2 with the `LoaderOptionsPlugin`. If you are faced with the `Cannot read property 'unsafeCache' of undefined` error then you probably need to supply a `resolve` object as below: (Thanks @jeffijoe!)
549
550```js
551new LoaderOptionsPlugin({
552 debug: false,
553 options: {
554 resolve: {
555 extensions: [".ts", ".tsx", ".js"]
556 }
557 }
558});
559```
560
561### Usage with Webpack watch
562
563Because 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:
564
565```js
566 plugins: [
567 new webpack.WatchIgnorePlugin([
568 /\.js$/,
569 /\.d\.ts$/
570 ])
571 ],
572```
573
574It's worth noting that use of the `LoaderOptionsPlugin` is [only supposed to be a stopgap measure](https://webpack.js.org/plugins/loader-options-plugin/). You may want to look at removing it entirely.
575
576### Hot Module replacement
577
578To enable `webpack-dev-server` HMR, you need to follow the official [Webpack HMR guide](https://webpack.js.org/guides/hot-module-replacement/), then tweak a few config options for `ts-loader`. The required configuration is as follows:
579
5801. Set `transpileOnly` to `true` (see [transpileOnly](#transpileonly-boolean-defaultfalse) for config details and recommendations above).
5812. Inside your HMR acceptance callback function, you must re-require the module that was replaced.
582
583For a boilerplate HMR project using React, check out the [react-hot-boilerplate example](./examples/react-hot-boilerplate/).
584
585For a minimal HMR TypeScript setup, go to the [hot-module-replacement example](./examples/hot-module-replacement/).
586
587## Contributing
588
589This is your TypeScript loader! We want you to help make it even better. Please feel free to contribute; see the [contributor's guide](CONTRIBUTING.md) to get started.
590
591## License
592
593MIT License