Skip to content
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

components not parsed by babel #736

Closed
Andarist opened this issue Dec 13, 2017 · 12 comments
Closed

components not parsed by babel #736

Andarist opened this issue Dec 13, 2017 · 12 comments

Comments

@Andarist
Copy link
Contributor

So my intention is to transpile svg with babel and from what I can see you try to parse components found with a pattern on your own and deduce from the output if the file exports a React Component. It would be great to load components files first with other webpack loaders and then decide if its exporting a React component.

  • Your style guide config (styleguide.config.js).
module.exports = {
	components: 'src/components/**/[A-Z]*.{js,svg}',
	showCode: true,
	showUsage: true,
	webpackConfig: config,
	styleguideComponents: {
		Wrapper: path.join(__dirname, './Wrapper'),
	},
}
  • Webpack version.
    latest
@sapegin
Copy link
Member

sapegin commented Dec 13, 2017

What issues you have with the current approach? It’s handled by react-docgen and it only works with the source code.

@Andarist
Copy link
Contributor Author

Well, I can't do any pre-compilation on my source files - in example svg -> js conversion. Transformed files could be stringified and passed to the react-docgen just fine. While I've managed to work around (for now) my svg problem, I think it would be nice to support i.e. babel macros, codegens etc and that would require transpiling stuff before passing it to react-docgen

@sapegin
Copy link
Member

sapegin commented Dec 13, 2017

Have you tested that your transpiled code actually works with react-docgen?

I think it would be nice to support i.e. babel macros, codegens etc

Sure, it may be a good idea.

@Andarist
Copy link
Contributor Author

Have you tested that your transpiled code actually works with react-docgen?

Yeah, I've worked around the issue with:

"icons": "babel src/components/Icons -x \".svg\" --out-dir src/components/Icons --no-babelrc --plugins react-svg,syntax-jsx",
"styleguide": "npm run icons && cross-env BABEL_ENV=es NODE_ENV=development styleguidist server",

and it works fine, but would be better to include this in more standard build pipeline - directly in styleguidist/webpack/babel configs instead of making an additional ninja script ;)

@sapegin
Copy link
Member

sapegin commented Dec 13, 2017

We can add a config option like transformSource(code) => transformedCode, sou you could apply any transformations like Babel before we send code to react-docgen, but it shouldn’t be some magic that we’ll enable by default — it works as is in 99% cases.

@piotrwitek
Copy link

piotrwitek commented Dec 17, 2017

@sapegin this would be really useful as I could use this transformer solution to handle a different use case:

  • I'd like to use Examples that I have written in seperate files with TypeScript, so then I can use them in code blocks, currently I have to use require, which is not and acceptable solution for me (because I want to see original component code in the code block, not just a require statement)

I need the transform to strip types and transpile it to ES6 before loading the source, otherwise it will have syntax errors.
Is this a good solution for my case, or you would suggest a different path?

@sapegin
Copy link
Member

sapegin commented Dec 17, 2017

@piotrwitek This issue is about transforming source code, not examples. I think you’re talking about #462.

@piotrwitek
Copy link

@sapegin now I got it (after reading development section), thanks and sorry for the noise

@Andarist
Copy link
Contributor Author

We can add a config option like transformSource(code) => transformedCode, sou you could apply any transformations like Babel before we send code to react-docgen, but it shouldn’t be some magic that we’ll enable by default — it works as is in 99% cases.

That would certainly make a better integration point.

@sapegin
Copy link
Member

sapegin commented Dec 17, 2017

@Andarist A pull request would make it much sooner ;-)

@Andarist
Copy link
Contributor Author

Sure thing, I'm willing to do this - just having many open PRs/ideas right now, so if anyone wants to do that before I get to it (eventually) feel free to do so!

@sapegin
Copy link
Member

sapegin commented Apr 2, 2018

I’m closing this for now. Feel free to submit a pull request if you need this.

@sapegin sapegin closed this as completed Apr 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants