Skip to content

Instantly share code, notes, and snippets.

@luiznasciment0
Created December 9, 2021 20:22
Show Gist options
  • Save luiznasciment0/c1b362bd1837c6049ad8a056840b087b to your computer and use it in GitHub Desktop.
Save luiznasciment0/c1b362bd1837c6049ad8a056840b087b to your computer and use it in GitHub Desktop.
storybook + typescript: how to setup path aliases in storybook, just as you did on your tsconfig file
/* first of all, install "tsconfig-paths-webpack-plugin" */
/* yarn add --dev tsconfig-paths-webpack-plugin */
/* then, integrate it with storybook's default main.js configuration */
// before:
module.exports = {
stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
addons: ['@storybook/addon-links', '@storybook/addon-essentials'],
framework: '@storybook/react',
};
// after:
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
module.exports = {
stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
addons: ['@storybook/addon-links', '@storybook/addon-essentials'],
framework: '@storybook/react',
webpackFinal: async (config) => {
config.resolve.plugins = [
...(config.resolve.plugins || []),
new TsconfigPathsPlugin({
extensions: config.resolve.extensions,
}),
];
return config;
},
};
// you should be good to go :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment