From 2fbed87803c47bb990f8958156bd232671d9256b Mon Sep 17 00:00:00 2001 From: JD Angerhofer Date: Wed, 6 Mar 2019 12:35:45 -0500 Subject: [PATCH] Docs: Typescript Configuration for v5 Updating Typescript example code to reflect Webpack "full control" mode in Storybook v5. --- .../configurations/typescript-config/index.md | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/docs/src/pages/configurations/typescript-config/index.md b/docs/src/pages/configurations/typescript-config/index.md index 9a400cd5ad2c..5ae2a0d7306d 100644 --- a/docs/src/pages/configurations/typescript-config/index.md +++ b/docs/src/pages/configurations/typescript-config/index.md @@ -25,21 +25,25 @@ We first have to use the [custom Webpack config in full control mode, extending ```js const path = require('path'); -module.exports = (baseConfig, env, config) => { +module.exports = ({ config, mode }) => { config.module.rules.push({ test: /\.(ts|tsx)$/, - use: [{ - loader: require.resolve('awesome-typescript-loader') - }, { - loader: require.resolve('react-docgen-typescript-loader') - }] + use: [ + { + loader: require.resolve('awesome-typescript-loader') + }, + // Optional + { + loader: require.resolve('react-docgen-typescript-loader') + } + ] }); config.resolve.extensions.push('.ts', '.tsx'); return config; }; ``` -The above example shows a working Webpack config with the TSDocgen plugin also integrated; remove the optional sections if you don't plan on using them. +The above example shows a working Webpack config with the [TSDocgen plugin](https://github.com/strothj/react-docgen-typescript-loader) integrated. This plugin is not necessary to use Storybook and the section marked `// optional` can be safely removed if the features of TSDocgen are not required. ### `tsconfig.json` @@ -91,13 +95,13 @@ yarn add -D @types/storybook__react # typings We first have to use the [custom Webpack config in full control mode, extending default configs](/configurations/custom-webpack-config/#full-control-mode--default) by creating a `webpack.config.js` file in our Storybook configuration directory (by default, it’s `.storybook`): ```js -module.exports = (baseConfig, env, config) => { +module.exports = ({ config, mode }) => { config.module.rules.push({ test: /\.(ts|tsx)$/, loader: require.resolve('babel-loader'), options: { - presets: [['react-app', { flow: false, typescript: true }]], - }, + presets: [['react-app', { flow: false, typescript: true }]] + } }); config.resolve.extensions.push('.ts', '.tsx'); return config;