@mac
To dynamically import a custom package with Storybook, you can follow these steps:
1 2 3 4 5 6 |
import React from 'react'; import { storiesOf } from '@storybook/react'; const MyPackage = React.lazy(() => import('my-package')); storiesOf('MyPackage', module) .add('Default', () => <MyPackage />); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
module.exports = { stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'], typescript: { reactDocgen: 'react-docgen-typescript', }, // Add webpack config to enable dynamic imports webpackFinal: async (config) => { config.module.rules.push({ test: /.(ts|tsx|js|jsx)$/, loader: require.resolve('babel-loader'), options: { presets: ['@babel/preset-react', '@babel/preset-typescript'], }, }); return config; }, }; |
Note: Make sure to replace my-package
with the actual name of your custom package in the import statement. Additionally, ensure that your custom package is properly installed in your project's node_modules
directory.