UNPKG

2.27 kBMarkdownView Raw
1<h1>Storybook TypeScript preset</h1>
2
3One-line TypeScript configuration for Storybook.
4
5- [Installation](#installation)
6- [Advanced usage](#advanced-usage)
7- [Options](#options)
8 - [forkTsCheckerWebpackPluginOptions](#forktscheckerwebpackpluginoptions)
9 - [include](#include)
10 - [transpileManager](#transpilemanager)
11
12## Installation
13
14First, install this preset to your project.
15
16```
17npm install -D @storybook/preset-typescript ts-loader fork-ts-checker-webpack-plugin # or yarn
18```
19
20Once installed, add this preset to the appropriate file:
21
22- `./.storybook/main.js` (for Storybook 5.3.0 and newer)
23
24 ```js
25 module.exports = {
26 addons: ['@storybook/preset-typescript'],
27 };
28 ```
29
30- `./.storybook/presets.js` (for all Storybook versions)
31
32 ```js
33 module.exports = ['@storybook/preset-typescript'];
34 ```
35
36## Advanced usage
37
38You can also pass extra configuration options to configure the preset. For example:
39
40```js
41// ./storybook/main.js
42const path = require('path');
43
44module.exports = {
45 addons: [
46 {
47 name: '@storybook/preset-typescript',
48 options: {
49 tsLoaderOptions: {
50 configFile: path.resolve(__dirname, './tsconfig.json'),
51 },
52 forkTsCheckerWebpackPluginOptions: {
53 colors: false, // disables built-in colors in logger messages
54 },
55 include: [path.resolve(__dirname, '../src')],
56 transpileManager: true,
57 },
58 },
59 ],
60};
61```
62
63All available options are described in the [Options](#options) section below.
64
65## Options
66
67### forkTsCheckerWebpackPluginOptions
68
69Type: `Object`
70
71<h5>Default value</h5>
72
73```js
74undefined;
75```
76
77[fork-ts-checker-webpack-plugin](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin#options) options. `transpileOnly` flag needs to be set to `true` in `tsLoaderOptions` to be able to set options for this webpack plugin.
78
79### include
80
81Type: [Rule condition](https://webpack.js.org/configuration/module/#rule-conditions)
82
83<h5>Default value</h5>
84
85```js
86undefined;
87```
88
89[include rule](https://webpack.js.org/configuration/module/#ruleinclude) for `/\.tsx?$/`.
90
91### transpileManager
92
93Type: `Boolean`
94
95<h5>Default value</h5>
96
97```js
98false;
99```
100
101Toggles TypeScript transpilation on [manager](https://storybook.js.org/docs/addons/writing-addons/) side.