Skip to content

Commit

Permalink
Improve compat of preset-typescript with Vue
Browse files Browse the repository at this point in the history
- remove ts docgen loader (rollup storybookjs#103)
- don't default to empty include option (rollup storybookjs#106)
- add appendTsSuffixTo to tsLoader options if framework is vue
  • Loading branch information
graup committed Feb 28, 2020
1 parent 7d2b2ae commit 05a0aa5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 23 deletions.
3 changes: 0 additions & 3 deletions packages/preset-typescript/.storybook/presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ module.exports = [
{
name: '@storybook/preset-typescript',
options: {
tsDocgenLoaderOptions: {
tsconfigPath: resolve(__dirname, '../tsconfig.json'),
},
forkTsCheckerWebpackPluginOptions: {
colors: false, // disables built-in colors in logger messages
},
Expand Down
2 changes: 0 additions & 2 deletions packages/preset-typescript/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { Configuration } from 'webpack';
import { Options as TSLoaderOptions } from 'ts-loader';
import TSDocgenLoaderOptions from 'react-docgen-typescript-loader/dist/LoaderOptions';

interface Options {
tsLoaderOptions?: TSLoaderOptions;
tsDocgenLoaderOptions?: TSDocgenLoaderOptions;
transpileManager?: boolean;
include?: string[];
}
Expand Down
36 changes: 20 additions & 16 deletions packages/preset-typescript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ function webpack(webpackConfig = {}, options = {}) {
const { module = {}, resolve = {}, plugins = [] } = webpackConfig;
const {
tsLoaderOptions = { transpileOnly: true },
tsDocgenLoaderOptions = {},
forkTsCheckerWebpackPluginOptions,
include = [],
include,
} = options;

if (tsLoaderOptions.transpileOnly) {
Expand All @@ -15,26 +14,31 @@ function webpack(webpackConfig = {}, options = {}) {
);
}

const tsLoader = {
test: /\.tsx?$/,
use: [
{
loader: require.resolve('ts-loader'),
options: tsLoaderOptions,
},
],
};

if (include) {
tsLoader.include = include;
}

if (options.framework === 'vue') {
tsLoaderOptions.appendTsSuffixTo = [...(tsLoaderOptions.appendTsSuffixTo || []), /\.vue$/];
}

return {
...webpackConfig,
module: {
...module,
rules: [
...(module.rules || []),
{
test: /\.tsx?$/,
use: [
{
loader: require.resolve('ts-loader'),
options: tsLoaderOptions,
},
{
loader: require.resolve('react-docgen-typescript-loader'),
options: tsDocgenLoaderOptions,
},
],
include,
},
tsLoader,
],
},
resolve: {
Expand Down
2 changes: 0 additions & 2 deletions packages/preset-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"babel-loader": "^8.0.2",
"fork-ts-checker-webpack-plugin": "^3.1.0",
"react": "^16.11.0",
"react-docgen-typescript-loader": "^3.3.0",
"react-dom": "^16.11.0",
"ts-loader": "^6.2.1",
"ts-node": "^7.0.0",
Expand All @@ -36,7 +35,6 @@
"peerDependencies": {
"@types/webpack": "*",
"fork-ts-checker-webpack-plugin": "*",
"react-docgen-typescript-loader": "*",
"ts-loader": "*",
"typescript": "^3.4"
}
Expand Down

0 comments on commit 05a0aa5

Please sign in to comment.