-
Notifications
You must be signed in to change notification settings - Fork 489
Using Storybook without ejecting #405
Comments
Hey @colinramsay! Yeah, you can use it w/o ejecting. const path = require("path");
const TSDocgenPlugin = require("react-docgen-typescript-webpack-plugin"); // Optional
module.exports = (baseConfig, env, config) => {
config.module.rules.push({
test: /\.(ts|tsx)$/,
loader: require.resolve("ts-loader")
});
config.plugins.push(new TSDocgenPlugin()); // optional
config.resolve.extensions.push(".ts", ".tsx");
return config;
};
import { configure } from '@storybook/react';
// automatically import all files ending in *.stories.js
const req = require.context('../', true, /.stories.tsx$/);
function loadStories() {
req.keys().forEach(filename => req(filename));
}
configure(loadStories, module); And in your "rootDirs": ["src", "stories"], |
Hey @colinramsay! Any news? 😉 |
I've tried it, and it works, though I have to use |
@r3nya for some reason the notification went to spam, I'll check this out and come back to you! |
@colinramsay oh, got it. Let me know if you will have any problems. ;) |
This is working perfectly now, thank you both! |
I take that back 😄 I have the following in tsconfig.json in the root of my project:
This allows me to import files using I tried changing the
No joy. Any ideas? |
I am not a webpack/tsconfig expert, but I know that it works out of the box sans I believe this is accomplished via either the "baseUrl" or "rootDir" compiler option, and is probably the reason I have to run the storybook command with |
@colinramsay The main thing that we have that is different from yours is that where you have I wonder if when running storybook from the top level directory your '..' paths are trying to apply from that level? Otherwise it should be pretty much standard - in tsconfig.json, {
"compilerOptions": {
"baseUrl": ".",
"paths": {
"src/*": ["src/*"] // you'd have "app/*": ["src/*"]
}
}
} and |
Changing to use |
I don't believe this is a bug, just an oversight. While the README says that Storybook (https://storybook.js.org/) will work, I think that's just copied over from CRA.
The Storybook docs (https://storybook.js.org/configurations/typescript-config/) seem to indicate that you'd need to eject to get it working.
Has anyone successful used Storybook +
create-react-app-typescript
without ejecting?The text was updated successfully, but these errors were encountered: