{"id":15043149,"url":"https://github.com/typestrong/ts-loader","last_synced_at":"2026-04-02T23:06:18.635Z","repository":{"id":26117445,"uuid":"29561893","full_name":"TypeStrong/ts-loader","owner":"TypeStrong","description":"TypeScript loader for webpack","archived":false,"fork":false,"pushed_at":"2025-03-03T18:03:42.000Z","size":6840,"stargazers_count":3473,"open_issues_count":81,"forks_count":433,"subscribers_count":39,"default_branch":"main","last_synced_at":"2025-05-01T13:50:59.213Z","etag":null,"topics":["loader","typescript","webpack","webpack-loader"],"latest_commit_sha":null,"homepage":"https://johnnyreilly.com/ts-loader-goes-webpack-5","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TypeStrong.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["johnnyreilly"]}},"created_at":"2015-01-21T00:00:16.000Z","updated_at":"2025-05-01T12:15:13.000Z","dependencies_parsed_at":"2024-01-28T12:25:11.778Z","dependency_job_id":"9b83f855-38d2-41db-90e8-8e4b93570387","html_url":"https://github.com/TypeStrong/ts-loader","commit_stats":{"total_commits":1151,"total_committers":157,"mean_commits":"7.3312101910828025","dds":0.5560382276281495,"last_synced_commit":"6a4e29c729fd6727c1c625fad3a65d509c2c37eb"},"previous_names":[],"tags_count":171,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TypeStrong%2Fts-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TypeStrong%2Fts-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TypeStrong%2Fts-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TypeStrong%2Fts-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TypeStrong","download_url":"https://codeload.github.com/TypeStrong/ts-loader/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253669539,"owners_count":21945109,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["loader","typescript","webpack","webpack-loader"],"created_at":"2024-09-24T20:48:38.245Z","updated_at":"2026-04-02T23:06:18.604Z","avatar_url":"https://github.com/TypeStrong.png","language":"TypeScript","readme":"# TypeScript loader for webpack\n\n[![npm version](https://img.shields.io/npm/v/ts-loader.svg)](https://www.npmjs.com/package/ts-loader)\n[![build and test](https://github.com/TypeStrong/ts-loader/actions/workflows/push.yml/badge.svg)](https://github.com/TypeStrong/ts-loader/actions/workflows/push.yml)\n[![Downloads](https://img.shields.io/npm/dm/ts-loader.svg)](https://npmjs.org/package/ts-loader)\n[![node version](https://img.shields.io/node/v/ts-loader.svg)](https://www.npmjs.com/package/ts-loader)\n[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)\n\n\u003cbr /\u003e\n\u003cp align=\"center\"\u003e\n  \u003ch3 align=\"center\"\u003ets-loader\u003c/h3\u003e\n\n  \u003cp align=\"center\"\u003e\n    This is the TypeScript loader for webpack.\n    \u003cbr /\u003e\n    \u003cbr /\u003e\n    \u003ca href=\"https://github.com/TypeStrong/ts-loader#installation\"\u003eInstallation\u003c/a\u003e\n    ·\n    \u003ca href=\"https://github.com/TypeStrong/ts-loader/issues\"\u003eReport Bug\u003c/a\u003e\n    ·\n    \u003ca href=\"https://github.com/TypeStrong/ts-loader/issues\"\u003eRequest Feature\u003c/a\u003e\n  \u003c/p\u003e\n\u003c/p\u003e\n\n## Table of Contents\n\n\u003c!-- toc --\u003e\n\n- [Getting Started](#getting-started)\n  * [Installation](#installation)\n  * [Running](#running)\n  * [Examples](#examples)\n  * [Faster Builds](#faster-builds)\n  * [Yarn Plug’n’Play](#yarn-plugnplay)\n  * [Babel](#babel)\n  * [Compatibility](#compatibility)\n  * [Configuration](#configuration)\n    + [`devtool` / sourcemaps](#devtool--sourcemaps)\n  * [Code Splitting and Loading Other Resources](#code-splitting-and-loading-other-resources)\n  * [Declarations (.d.ts)](#declaration-files-dts)\n  * [Failing the build on TypeScript compilation error](#failing-the-build-on-typescript-compilation-error)\n  * [`baseUrl` / `paths` module resolution](#baseurl--paths-module-resolution)\n  * [Options](#options)\n  * [Loader Options](#loader-options)\n    + [transpileOnly](#transpileonly)\n    + [happyPackMode](#happypackmode)\n    + [resolveModuleName and resolveTypeReferenceDirective](#resolvemodulename-and-resolvetypereferencedirective)\n    + [getCustomTransformers](#getcustomtransformers)\n    + [logInfoToStdOut](#loginfotostdout)\n    + [logLevel](#loglevel)\n    + [silent](#silent)\n    + [ignoreDiagnostics](#ignorediagnostics)\n    + [reportFiles](#reportfiles)\n    + [compiler](#compiler)\n    + [configFile](#configfile)\n    + [colors](#colors)\n    + [errorFormatter](#errorformatter)\n    + [compilerOptions](#compileroptions)\n    + [instance](#instance)\n    + [appendTsSuffixTo](#appendtssuffixto)\n    + [appendTsxSuffixTo](#appendtsxsuffixto)\n    + [onlyCompileBundledFiles](#onlycompilebundledfiles)\n    + [useCaseSensitiveFileNames](#useCaseSensitiveFileNames)\n    + [allowTsInNodeModules](#allowtsinnodemodules)\n    + [context](#context)\n    + [experimentalFileCaching](#experimentalfilecaching)\n    + [projectReferences](#projectreferences)\n  * [Usage with webpack watch](#usage-with-webpack-watch)\n  * [Hot Module replacement](#hot-module-replacement)\n- [Contributing](#contributing)\n- [License](#license)\n\n\u003c!-- tocstop --\u003e\n\n## Getting Started\n\n### Installation\n\n```\nyarn add ts-loader --dev\n```\n\nor\n\n```\nnpm install ts-loader --save-dev\n```\n\nYou will also need to install TypeScript if you have not already.\n\n```\nyarn add typescript --dev\n```\n\nor\n\n```\nnpm install typescript --save-dev\n```\n\n### Running\n\nUse webpack like normal, including `webpack --watch` and `webpack-dev-server`, or through another\nbuild system using the [Node.js API](https://webpack.js.org/api/node/).\n\n### Examples\n\nWe have a number of example setups to accommodate different workflows. Our examples can be found [here](examples/).\n\nWe probably have more examples than we need.  That said, here's a good way to get started:\n\n- I want the simplest setup going.  Use \"[vanilla](examples/vanilla)\" `ts-loader`\n- I want the fastest compilation that's available.  Use [fork-ts-checker-webpack-plugin](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin).  It performs type checking in a separate process with `ts-loader` just handling transpilation.\n\n### Faster Builds\n\nAs your project becomes bigger, compilation time increases linearly. It's because typescript's semantic checker has to inspect all files on every rebuild. \nThe 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*.\n\nYou 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/TypeStrong/fork-ts-checker-webpack-plugin).\nIt runs the type checker on a separate process, so your build remains fast thanks to `transpileOnly: true` but you still have the type checking.\n\nIf you'd like to see a simple setup take a look at [our example](examples/fork-ts-checker-webpack-plugin/).\n\n### Yarn Plug’n’Play\n\n`ts-loader` supports [Yarn Plug’n’Play](https://yarnpkg.com/en/docs/pnp).  The recommended way to integrate is using the [pnp-webpack-plugin](https://github.com/arcanis/pnp-webpack-plugin#ts-loader-integration).\n\n### Babel\n\n`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). \n\n### Compatibility\n\n* TypeScript: 3.6.3+\n* webpack: 5.x+ (please use `ts-loader` 8.x if you need webpack 4 support)\n* node: 12.x+\n\nA full test suite runs each night (and on each pull request). It runs both on Linux and Windows, 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).\n\nIf 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!\n\n### Configuration\n\n1. Create or update `webpack.config.js` like so:\n\n   ```javascript\n   module.exports = {\n     mode: \"development\",\n     devtool: \"inline-source-map\",\n     entry: \"./app.ts\",\n     output: {\n       filename: \"bundle.js\"\n     },\n     resolve: {\n       // Add `.ts` and `.tsx` as a resolvable extension.\n       extensions: [\".ts\", \".tsx\", \".js\"],\n       // Add support for TypeScripts fully qualified ESM imports.\n       extensionAlias: {\n        \".js\": [\".js\", \".ts\"],\n        \".cjs\": [\".cjs\", \".cts\"],\n        \".mjs\": [\".mjs\", \".mts\"]\n       }\n     },\n     module: {\n       rules: [\n         // all files with a `.ts`, `.cts`, `.mts` or `.tsx` extension will be handled by `ts-loader`\n         { test: /\\.([cm]?ts|tsx)$/, loader: \"ts-loader\" }\n       ]\n     }\n   };\n   ```\n\n2. 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)\n\n   ```json\n   {\n     \"compilerOptions\": {\n       \"sourceMap\": true\n     }\n   }\n   ```\n\nThe [tsconfig.json](http://www.typescriptlang.org/docs/handbook/tsconfig-json.html) file controls\nTypeScript-related options so that your IDE, the `tsc` command, and this loader all share the\nsame options.\n\n#### `devtool` / sourcemaps\n\nIf 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.\n\nFirst, 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`.\n\nSecond, 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:\n\n* `devtool: 'inline-source-map'` - Solid sourcemap support; the best \"all-rounder\". Works well with karma-webpack (not all strategies do)\n* `devtool: 'eval-cheap-module-source-map'` - Best support for sourcemaps whilst debugging.\n* `devtool: 'source-map'` - Approach that plays well with UglifyJsPlugin; typically you might use this in Production\n\n### Code Splitting and Loading Other Resources\n\nLoading css and other resources is possible but you will need to make sure that\nyou have defined the `require` function in a [declaration file](https://www.typescriptlang.org/docs/handbook/writing-declaration-files.html).\n\n```typescript\ndeclare var require: {\n  \u003cT\u003e(path: string): T;\n  (paths: string[], callback: (...modules: any[]) =\u003e void): void;\n  ensure: (\n    paths: string[],\n    callback: (require: \u003cT\u003e(path: string) =\u003e T) =\u003e void\n  ) =\u003e void;\n};\n```\n\nThen you can simply require assets or chunks per the [webpack documentation](https://webpack.js.org/guides/code-splitting/).\n\n```javascript\nrequire(\"!style!css!./style.css\");\n```\n\nThe same basic process is required for code splitting. In this case, you `import` modules you need but you\ndon't directly use them. Instead you require them at [split points](https://webpack.js.org/guides/code-splitting/). See [this example](test/comparison-tests/codeSplitting) and [this example](test/comparison-tests/es6codeSplitting) for more details.\n\n[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!\n\n### Declaration Files (.d.ts)\n\nTo output declaration files (.d.ts), you can set \"declaration\": true in your tsconfig and set \"transpileOnly\" to false.\n\nIf you use ts-loader with  \"transpileOnly\": true along with [fork-ts-checker-webpack-plugin](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin), you will need to configure fork-ts-checker-webpack-plugin to output definition files, you can learn more on the plugin's documentation page: https://github.com/TypeStrong/fork-ts-checker-webpack-plugin#typescript-options\n\nTo output a built .d.ts file, you can use the [DeclarationBundlerPlugin](https://www.npmjs.com/package/types-webpack-bundler) in your webpack config.\n\n### Failing the build on TypeScript compilation error\n\nThe 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).\n\nFor more background have a read of [this issue](https://github.com/TypeStrong/ts-loader/issues/108).\n\n### `baseUrl` / `paths` module resolution\n\nIf 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).\n\nThis 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.\n\n```javascript\nconst TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');\n\nmodule.exports = {\n  ...\n  resolve: {\n    plugins: [new TsconfigPathsPlugin({ configFile: \"./path/to/tsconfig.json\" })]\n  }\n  ...\n}\n```\n\n### Options\n\nThere 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:\n\n```javascript\nmodule.exports = {\n  ...\n  module: {\n    rules: [\n      {\n        test: /\\.tsx?$/,\n        use: [\n          {\n            loader: 'ts-loader',\n            options: {\n              transpileOnly: true\n            }\n          }\n        ]\n      }\n    ]\n  }\n}\n```\n\n### Loader Options\n\n#### transpileOnly\n| Type | Default Value |\n|------|--------------|\n| `boolean` | `false`|\n\nIf you want to speed up compilation significantly you can set this flag.\nHowever, many of the benefits you get from static type checking between different dependencies in your application will be lost. `transpileOnly` will *not* speed up compilation of project references.\n\nIt's advisable to use `transpileOnly` alongside the [fork-ts-checker-webpack-plugin](https://github.com/TypeStrong/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 example](examples/fork-ts-checker-webpack-plugin).\n\n\u003e Tip: When you add the [fork-ts-checker-webpack-plugin](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin) to your webpack config, the `transpileOnly` will default to `true`, so you can skip that option.\n\nIf you enable this option, webpack 4 will give you \"export not found\" warnings any time you re-export a type:\n\n```\nWARNING in ./src/bar.ts\n1:0-34 \"export 'IFoo' was not found in './foo'\n @ ./src/bar.ts\n @ ./src/index.ts\n```\n\nThe 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:\n\n```javascript\nmodule.exports = {\n  ...\n  stats: {\n    warningsFilter: /export .* was not found in/\n  }\n}\n```\n\n#### happyPackMode\n| Type | Default Value |\n|------|--------------|\n| `boolean` | `false`|\n\nIf you're using [HappyPack](https://github.com/amireh/happypack) or [thread-loader](https://github.com/webpack-contrib/thread-loader) to parallelise 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.\n\nIt's advisable to use this with the [fork-ts-checker-webpack-plugin](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin) to get full type checking again. **_IMPORTANT_**: If you are using fork-ts-checker-webpack-plugin alongside HappyPack or thread-loader then ensure you set the `syntactic` diagnostic option like so:\n\n```javascript\n        new ForkTsCheckerWebpackPlugin({\n          typescript: {\n            diagnosticOptions: {\n              semantic: true,\n              syntactic: true,\n            },\n          },\n        })\n```\n\nThis 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).\n\nAlso, if you are using `thread-loader` in watch mode, remember to set `poolTimeout: Infinity` so workers don't die.\n\n#### resolveModuleName and resolveTypeReferenceDirective\n\nThese options should be functions which will be used to resolve the import statements and the `\u003creference types=\"...\"\u003e` directives instead of the default TypeScript implementation. It's not intended that these will typically be used by a user of `ts-loader` - they exist to facilitate functionality such as [Yarn Plug’n’Play](https://yarnpkg.com/en/docs/pnp).\n\n#### getCustomTransformers\n| Type |\n|------|\n| ` (program: Program, getProgram: () =\u003e Program) =\u003e { before?: TransformerFactory\u003cSourceFile\u003e[]; after?: TransformerFactory\u003cSourceFile\u003e[]; afterDeclarations?: TransformerFactory\u003cSourceFile\u003e[]; } ` |\n\nProvide 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).\n\nYou 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 processes cannot serialize functions see more at [related issue](https://github.com/Igorbek/typescript-plugin-styled-components/issues/6#issue-303387183))\n\n#### logInfoToStdOut\n| Type | Default Value |\n|------|--------------|\n| `boolean` | `false`|\n\nThis is important if you read from stdout or stderr and for proper error handling.\nThe default value ensures that you can read from stdout e.g. via pipes or you use webpack -j to generate json output.\n\n#### logLevel\n| Type | Default Value |\n|------|--------------|\n| `string` | `warn` |\n\nCan be `info`, `warn` or `error` which limits the log output to the specified log level.\nBeware of the fact that errors are written to stderr and everything else is written to stderr (or stdout if logInfoToStdOut is true).\n\n#### silent\n| Type | Default Value |\n|------|--------------|\n| `boolean` | `false`|\n\nIf `true`, no console.log messages will be emitted. Note that most error\nmessages are emitted via webpack which is not affected by this flag.\n\n#### ignoreDiagnostics\n| Type | Default Value |\n|------|--------------|\n| `number[]` | `[]`|\n\nYou can squelch certain TypeScript errors by specifying an array of diagnostic\ncodes to ignore.\n\n#### reportFiles\n| Type | Default Value |\n|------|--------------|\n| `string[]` | `[]`|\n\nOnly report errors on files matching these glob patterns.\n\n```javascript\n  // in webpack.config.js\n  {\n    test: /\\.ts$/,\n    loader: 'ts-loader',\n    options: { reportFiles: ['src/**/*.{ts,tsx}', '!src/skip.ts'] }\n  }\n```\n\nThis can be useful when certain types definitions have errors that are not fatal to your application.\n\n#### compiler\n| Type | Default Value |\n|------|--------------|\n| `string` | `'typescript'`|\n\nAllows use of TypeScript compilers other than the official one. Should be\nset to the NPM name of the compiler, eg [`ntypescript`](https://github.com/basarat/ntypescript).\n\n#### configFile\n| Type | Default Value |\n|------|--------------|\n| `string` | `'tsconfig.json'`|\n\nAllows you to specify where to find the TypeScript configuration file.\n\nYou may provide\n\n* 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.\n* a relative path to the configuration file. It will be resolved relative to the respective `.ts` entry file.\n* an absolute path to the configuration file.\n\nPlease 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).\nIn this case the `configFile` should point to the `tsconfig.json` and `context` to the project root.\n\n#### colors\n| Type | Default Value |\n|------|--------------|\n| `boolean` | `true`|\n\nIf `false`, disables built-in colors in logger messages.\n\n#### errorFormatter\n| Type | Default Value |\n|------|--------------|\n| `(message: ErrorInfo, colors: boolean) =\u003e string` | `undefined`|\n\nBy default `ts-loader` formats TypeScript compiler output for an error or a warning in the style:\n\n```\n[tsl] ERROR in myFile.ts(3,14)\n      TS4711: you did something very wrong\n```\n\nIf 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.)\n\n```javascript\nfunction customErrorFormatter(error, colors) {\n  const messageColor =\n    error.severity === \"warning\" ? colors.bold.yellow : colors.bold.red;\n  return (\n    \"Does not compute.... \" +\n    messageColor(Object.keys(error).map(key =\u003e `${key}: ${error[key]}`))\n  );\n}\n```\n\nIf the above formatter received an error like this:\n\n```json\n{\n  \"code\":2307,\n  \"severity\": \"error\",\n  \"content\": \"Cannot find module 'components/myComponent2'.\",\n  \"file\":\"/.test/errorFormatter/app.ts\",\n  \"line\":2,\n  \"character\":31\n}\n```\n\nIt would produce an error message that said:\n\n```\nDoes not compute.... code: 2307,severity: error,content: Cannot find module 'components/myComponent2'.,file: /.test/errorFormatter/app.ts,line: 2,character: 31\n```\n\nAnd the bit after \"Does not compute.... \" would be red.\n\n#### compilerOptions\n| Type | Default Value |\n|------|--------------|\n| `object` | `{}`|\n\nAllows overriding TypeScript options. Should be specified in the same format\nas you would do for the `compilerOptions` property in tsconfig.json.\n\n#### instance\n| Type | Default Value |\n|------|--------------|\n| `string` | `TODO`|\n\nAdvanced option to force files to go through different instances of the\nTypeScript compiler. Can be used to force segregation between different parts\nof your code.\n\n#### appendTsSuffixTo\n| Type | Default Value |\n|------|--------------|\n| `(RegExp \\| string)[]` | `[]`|\n\n#### appendTsxSuffixTo\n| Type | Default Value |\n|------|--------------|\n| `(RegExp \\| string)[]` | `[]`|\n\nA 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.\nIf you're using [HappyPack](https://github.com/amireh/happypack) or [thread-loader](https://github.com/webpack-contrib/thread-loader) with `ts-loader`, you need use the `string` type for the regular expressions, not `RegExp` object.\n\n```js\n// change this:\n{ appendTsSuffixTo: [/\\.vue$/] }\n// to:\n{ appendTsSuffixTo: ['\\\\.vue$'] }\n```\n\n\nThis 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.)\n\nExample:\n\nwebpack.config.js:\n\n```javascript\nmodule.exports = {\n  entry: \"./index.vue\",\n  output: { filename: \"bundle.js\" },\n  resolve: {\n    extensions: [\".ts\", \".vue\"]\n  },\n  module: {\n    rules: [\n      { test: /\\.vue$/, loader: \"vue-loader\" },\n      {\n        test: /\\.ts$/,\n        loader: \"ts-loader\",\n        options: { appendTsSuffixTo: [/\\.vue$/] }\n      }\n    ]\n  }\n};\n```\n\nindex.vue\n\n```vue\n\u003ctemplate\u003e\u003cp\u003ehello {{msg}}\u003c/p\u003e\u003c/template\u003e\n\u003cscript lang=\"ts\"\u003e\nexport default {\n  data(): Object {\n    return {\n      msg: \"world\"\n    };\n  }\n};\n\u003c/script\u003e\n```\n\nWe can handle `.tsx` by quite similar way:\n\nwebpack.config.js:\n\n```javascript\nmodule.exports = {\n    entry: './index.vue',\n    output: { filename: 'bundle.js' },\n    resolve: {\n        extensions: ['.ts', '.tsx', '.vue', '.vuex']\n    },\n    module: {\n        rules: [\n            { test: /\\.vue$/, loader: 'vue-loader',\n              options: {\n                loaders: {\n                  ts: 'ts-loader',\n                  tsx: 'babel-loader!ts-loader',\n                }\n              }\n            },\n            { test: /\\.ts$/, loader: 'ts-loader', options: { appendTsSuffixTo: [/TS\\.vue$/] } }\n            { test: /\\.tsx$/, loader: 'babel-loader!ts-loader', options: { appendTsxSuffixTo: [/TSX\\.vue$/] } }\n        ]\n    }\n}\n```\n\ntsconfig.json (set `jsx` option to `preserve` to let babel handle jsx)\n\n```json\n{\n  \"compilerOptions\": {\n    \"jsx\": \"preserve\"\n  }\n}\n```\n\nindex.vue\n\n```vue\n\u003cscript lang=\"tsx\"\u003e\nexport default {\n  functional: true,\n  render(h, c) {\n    return (\u003cdiv\u003eContent\u003c/div\u003e);\n  }\n}\n\u003c/script\u003e\n```\n\nOr if you want to use only tsx, just use the `appendTsxSuffixTo` option only:\n\n```javascript\n            { test: /\\.ts$/, loader: 'ts-loader' }\n            { test: /\\.tsx$/, loader: 'babel-loader!ts-loader', options: { appendTsxSuffixTo: [/\\.vue$/] } }\n```\n\n#### onlyCompileBundledFiles\n| Type | Default Value |\n|------|--------------|\n| `boolean` | `false`|\n\nThe default behavior of `ts-loader` is to act as a drop-in replacement for the `tsc` command,\nso it respects the `include`, `files`, and `exclude` options in your `tsconfig.json`, loading\nany files specified by those options. The `onlyCompileBundledFiles` option modifies this behavior,\nloading only those files that are actually bundled by webpack, as well as any `.d.ts` files included\nby the `tsconfig.json` settings. `.d.ts` files are still included because they may be needed for\ncompilation without being explicitly imported, and therefore not picked up by webpack.\n\n#### useCaseSensitiveFileNames\n| Type | Default Value |\n|------|--------------|\n| `boolean` | determined by typescript based on platform |\n\nThe default behavior of `ts-loader` is to act as a drop-in replacement for the `tsc` command,\nso it respects the `useCaseSensitiveFileNames` set internally by typescript. The `useCaseSensitiveFileNames` option modifies this behavior,\nby changing the way in which ts-loader resolves file paths to compile. Setting this to true can have some performance benefits due to simplifying the file resolution codepath.\n\n#### allowTsInNodeModules\n| Type | Default Value |\n|------|--------------|\n| `boolean` | `false`|\n\nBy default, `ts-loader` will not compile `.ts` files in `node_modules`.\nYou should not need to recompile `.ts` files there, but if you really want to, use this option.\nNote that this option acts as a *whitelist* - any modules you desire to import must be included in\nthe `\"files\"` or `\"include\"` block of your project's `tsconfig.json`.\n\nSee: [https://github.com/Microsoft/TypeScript/issues/12358](https://github.com/Microsoft/TypeScript/issues/12358)\n\n```javascript\n  // in webpack.config.js\n  {\n    test: /\\.ts$/,\n    loader: 'ts-loader',\n    options: { allowTsInNodeModules: true }\n  }\n```\n\nAnd in your `tsconfig.json`:\n\n```json\n  {\n    \"include\": [\n      \"node_modules/whitelisted_module.ts\"\n    ],\n    \"files\": [\n      \"node_modules/my_module/whitelisted_file.ts\"\n    ]\n  }\n```\n\n#### context\n| Type | Default Value |\n|------|--------------|\n| `string` | `undefined`|\n\nIf set, will parse the TypeScript configuration file with given **absolute path** as base path.\nPer default the directory of the configuration file is used as base path. Relative paths in the configuration\nfile are resolved with respect to the base path when parsed. Option `context` allows to set option\n`configFile` to a path other than the project root (e.g. a NPM package), while the base path for `ts-loader`\ncan remain the project root.\n\nKeep in mind that **not** having a `tsconfig.json` in your project root can cause different behaviour between `ts-loader` and `tsc`.\nWhen 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\nreferenced in option `configFile`. For more information please [read the PR](https://github.com/TypeStrong/ts-loader/pull/681) that\nis the base and [read the PR](https://github.com/TypeStrong/ts-loader/pull/688) that contributed this option.\n\nwebpack:\n\n```javascript\n{\n  loader: require.resolve('ts-loader'),\n  options: {\n    context: __dirname,\n    configFile: require.resolve('ts-config-react-app')\n  }\n}\n```\n\nExtending `tsconfig.json`:\n\n```json\n{ \"extends\": \"./node_modules/ts-config-react-app/index\" }\n```\n\nNote that changes in the extending file while not be respected by `ts-loader`. Its purpose is to satisfy the code editor.\n\n#### experimentalFileCaching\n| Type | Default Value |\n|------|--------------|\n| `boolean` | `true`|\n\nBy default whenever the TypeScript compiler needs to check that a file/directory exists or resolve symlinks it makes syscalls. It does not cache the result of these operations and this may result in many syscalls with the same arguments ([see comment](https://github.com/TypeStrong/ts-loader/issues/825#issue-354725524) with example).\nIn some cases it may produce performance degradation.\n\nThis flag enables caching for some FS-functions like `fileExists`, `realpath` and `directoryExists` for TypeScript compiler. Note that caches are cleared between compilations.\n\n#### projectReferences\n| Type | Default Value |\n|------|--------------|\n| `boolean` | `false`|\n\nts-loader has opt-in support for [project references](https://www.typescriptlang.org/docs/handbook/project-references.html). With this configuration option enabled, `ts-loader` will incrementally rebuild upstream projects the same way `tsc --build` does. Otherwise, source files in referenced projects will be treated as if they’re part of the root project.\n\nIn order to make use of this option your project needs to be correctly configured to build the project references and then to use them as part of the build. See the [Project References Guide](REFERENCES.md) and the example code in the examples which can be found [here](examples/project-references-example/).\n\n### Usage with webpack watch\n\nBecause 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:\n\n```javascript\n// for webpack 4\n plugins: [\n   new webpack.WatchIgnorePlugin([\n     /\\.js$/,\n     /\\.d\\.[cm]?ts$/\n   ])\n ],\n\n// for webpack 5\nplugins: [\n  new webpack.WatchIgnorePlugin({\n    paths:[\n      /\\.js$/,\n      /\\.d\\.[cm]ts$/\n  ]})\n],\n```\n\nIt'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.\n\n### Hot Module replacement\n\nWe do not support HMR as we did not yet work out a reliable way how to set it up.\n\nIf you want to give `webpack-dev-server` HMR a try, follow the official [webpack HMR guide](https://webpack.js.org/guides/hot-module-replacement/), then tweak a few config options for `ts-loader`:\n\n1. Set `transpileOnly` to `true` (see [transpileOnly](#transpileonly) for config details and recommendations above).\n2. Inside your HMR acceptance callback function, maybe re-require the module that was replaced.\n\n## Contributing\n\nThis 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.\n\n## History\n\n`ts-loader` was started by [James Brantly](https://github.com/jbrantly), since 2016 [John Reilly](https://github.com/johnnyreilly) has been taking good care of it. If you're interested, you can [read more about how that came to pass](https://johnnyreilly.com/but-you-cant-die-i-love-you-ts-loader).\n\n## License\n\nMIT License\n","funding_links":["https://github.com/sponsors/johnnyreilly"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftypestrong%2Fts-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftypestrong%2Fts-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftypestrong%2Fts-loader/lists"}