From 2d0977005565a2fd98a5f4cf13b995d5ca03b639 Mon Sep 17 00:00:00 2001 From: Christian Tinauer Date: Sat, 18 Nov 2017 16:10:34 +0100 Subject: [PATCH] Add description of option "contextAsConfigBasePath" to README. --- README.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/README.md b/README.md index c6733a3aa..352cd0239 100644 --- a/README.md +++ b/README.md @@ -410,6 +410,39 @@ loading only those files that are actually bundled by webpack, as well as any `. by the `tsconfig.json` settings. `.d.ts` files are still included because they may be needed for compilation without being explicitly imported, and therefore not picked up by webpack. +#### contextAsConfigBasePath *(boolean) (default=false)* + +If true, will parse the TypeScript configuration file with +[webpack.context](https://webpack.js.org/configuration/entry-context/#context) as base path. +Per default the directory of the configuration file is used as base path. Relative paths in the configuration +file are resolved with respect to the base path when parsed. Option `contextAsConfigBasePath` allows to set option +`configFile` to a path other than the project root (e.g. a NPM package) and the base path for `ts-loader` is [webpack.context](https://webpack.js.org/configuration/entry-context/#context) (which is most of the time the project root). + +Keep in mind that **not** having a `tsconfig.json` in your project root can cause different behaviour between `ts-loader` and `tsc`. +When 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 +referenced in option `configFile`. + +Webpack: + +```javascript +{ + loader: require.resolve('ts-loader'), + options: { + contextAsConfigBasePath: true, + configFile: require.resolve('ts-config-react-app') + } +} + +``` + +Extending `tsconfig.json`: + +```json +{ "extends": "./node_modules/ts-config-react-app/index" } +``` + +Note that changes in the extending file while not be respected by `ts-loader`. Its purpose is to satisfy the code editor. + ### `LoaderOptionsPlugin` [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!)