-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Docz to work with Create React App webpack config #1382
Comments
Hey @chmurson, docz should be able to work with create-react-app out of the box in JS projects and for TS projects by adding Could you share an example for what you mean by different svg files handling ? |
Hey @rakannimer, The reason is because CRA supports following way of rendering svgs: import { ReactComponent as Logo} from './logo.svg';
//somewhere in render function
<div><Logo/></div> more info: https://create-react-app.dev/docs/adding-images-fonts-and-files/#adding-svgs The above method does not work in Docz, because CRA uses some custom babel plugin that makes it possible to import both as react and inline data string. One of the workarounds for this to work in Docz is solution I posted in the first post. I've managed to replicate the issue on forked Docz repo: https://github.com/chmurson/docz. Please take a look at the modified example: https://github.com/chmurson/docz/tree/master/examples/create-react-app-ts. The
I was not able to find any other issue, so I think apart of that tiny issue, Docz works great with TS and with CRA. :) |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
FYI for those who end up here, this can be fixed by installing |
It looks like before the PR merged, you can copy the |
Situation
There is a project I work with, that is set up via Create React App with Typescript support. The choice was to use Docz to setup live documentation for components implemented in it.
Problem
Components that were working nicely in CRA, were not working in Docz. The reason was different way of handling SVG files between those two project. That was the initial reason, there might be more differences.
Solution
To modify Gatsby's webpack config, I went with steps from here https://www.gatsbyjs.org/docs/add-custom-webpack-config. I extracted babel-loader rule config from CRA webpack and injected it in Gatbsy's config, replacing the its babel-loader rule.
Following code is specific Typescirpty. For e.g. pure JS
'tsx'
could be replaced with'jsx'
or some more generic code that works with all possible cases.Feature request / Feature suggestion
I'm new do Docz and to Gatsby, so it took me a heap of time to figure it out, and implement the workaround. I think it would be nice to have solution working out-of-the-box, e.g. Docz takes CRA's webpack config automatically (Storybook and Styleguidist do this). If that is not feasible, it would be nice to have some words in documentation or maybe even example with create-react-app updated.
The reason I'm posting it here, not on Gatsby repo is because it is not obvious why would anyone mix two technologies like Gatsby and CRA. I can imagine the value in it is not clear, in contrast to mixing Docz and CRA.
The text was updated successfully, but these errors were encountered: