UNPKG

3.68 kBMarkdownView Raw
1# tsconfig-paths-webpack-plugin
2
3[![npm version][version-image]][version-url]
4[![code style: prettier][prettier-image]][prettier-url]
5[![MIT license][license-image]][license-url]
6
7Use this to load modules whose location is specified in the `paths` section of
8`tsconfig.json` when using webpack. This package provides the functionality of
9the [tsconfig-paths](https://www.npmjs.com/package/tsconfig-paths) package but
10as a webpack plug-in.
11
12## How to install
13
14```
15yarn add --dev tsconfig-paths-webpack-plugin
16```
17
18or
19
20```
21npm install --save-dev tsconfig-paths-webpack-plugin
22```
23
24## How to use
25
26In your webpack config add this:
27
28```js
29const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
30
31module.exports = {
32 ...
33 resolve: {
34 plugins: [new TsconfigPathsPlugin({ /*configFile: "./path/to/tsconfig.json" */ })]
35 }
36 ...
37}
38```
39
40## Options
41
42#### configFile _(string) (default='tsconfig.json')_
43
44Allows you to specify where to find the TypeScript configuration file.
45
46You may provide
47
48* just a file name. The plugin will search for the filename using the built-in
49 logic in the `tsconfig-paths` package. The search will start at `cwd`.
50* a relative path to the configuration file. It will be resolved relative to
51 `cwd`.
52* an absolute path to the configuration file.
53
54> The use of `cwd` as default above is not optimal but we've found no better
55> solution yet. If you have a suggestion please file an issue.
56
57#### extensions _(string[]) (default=[".ts", ".tsx"])_
58
59An array of the extensions that will be tried during resolve. Ideally this would be the same as the extensions form the webpack config but it seems resolver plug-ins does not have access to this infomration so you need to specify it again for the plugin.
60
61#### baseUrl _(string) (default=undefined)_
62
63This allows you to override the `baseUrl` found in tsconfig.json. The baseUrl specifies from which directory `paths` should be resolved. So this option enabled you to resolve from anhother directory than the one where tsconfig.json is located. This can be useful if you want to use webpack with `tsc --watch` instead of a typescript loader. If this option is `undefined` then the `baseUrl` from tsconfig.json will be used.
64
65#### silent _(boolean) (default=false)_
66
67If true, no console.log messages will be emitted. Note that most error messages
68are emitted via webpack which is not affected by this flag.
69
70#### logLevel _(string) (default=warn)_
71
72Can be `info`, `warn` or `error` which limits the log output to the specified
73log level. Beware of the fact that errors are written to stderr and everything
74else is written to stderr (or stdout if logInfoToStdOut is true).
75
76#### colors _(boolean) (default=true)_
77
78If `false`, disables built-in colors in logger messages.
79
80#### logInfoToStdOut _(boolean) (default=false)_
81
82This is important if you read from stdout or stderr and for proper error
83handling. The default value ensures that you can read from stdout e.g. via pipes
84or you use webpack -j to generate json output.
85
86## How to test
87
88To run the provided example:
89
90```
91yarn example
92```
93
94## Prior work
95
96This project uses work done in the
97[awesome-typescript-loader](https://github.com/s-panferov/awesome-typescript-loader).
98
99[version-image]: https://img.shields.io/npm/v/tsconfig-paths-webpack-plugin.svg?style=flat
100[version-url]: https://www.npmjs.com/package/tsconfig-paths-webpack-plugin
101[prettier-image]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat
102[prettier-url]: https://github.com/prettier/prettier
103[license-image]: https://img.shields.io/github/license/jonaskello/tsconfig-paths-webpack-plugin.svg?style=flat
104[license-url]: https://opensource.org/licenses/MIT