-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
How to publish components without ejecting #796
Comments
Would you like to add |
I think that would be really useful. |
It would indeed be useful. I used your setup myself and it works great. But I have a problem with CSS. I have a few stylesheets (one per component) that I import via Webpack (as described in the User guide). However, the stylesheets are not copied into lib when using Babel. So I had to extract the stylesheets in an index.css file and npm install
It works but it does require putting all your css in one file. I don't know how to do better. |
@gaearon Could create-react-app generate .babelrc file with |
We want to hide dev dependencies and their versions, so I would like to avoid that. I understand the motivation in this issue but it's a slightly more advanced use case, and so we don't have a clean support for it. I think that after we implement #741, we might take a look at supporting building/publishing components with that package structure. |
@emilebres, is the idea that you're putting everything into one CSS file to simplify consumption, since only one CSS file has to be imported in addition to the code itself? |
That's certainly one advantage yes. |
Thanks @emilebres, good to know. The problem I'm facing is that the components I want to compile are using CSS modules, which creates its own additional set of problems. I'm more & more preferring the atomic functional CSS approach over both style-in-js and CSS Modules, since it solves this and many other styling & theming related issues. |
I would love to contribute to this, as I will have to do a POC in implementing thing like this for my new project. http://github.com/mappmechanic/codelab-book @gaearon - Please do guide me if I should do a Prototype with that Babel Preset thing or some other approach. |
I'll close as this is currently out of scope of the project. I recommend nwb for publishing components. |
For a very simple start to uncompiled typescript components, this might make a good read. Its done for vanilla Typescript components but principles should cross over to TSX If anyone wants I can look at TSX. |
I hope others find this useful.
I have a project built using CRA that includes some components I wish to publish on npm. In order to do that I need to use babel to transpile the code to ES5.
Out of the box, babel is not available from a
package.json
script and I really don't want to eject. So I made this work by npm installingbabel-cli
andbabel-preset-react-app
and then adding acompile
script that looks something like this:set NODE_ENV=production&&babel -d lib/ src/ --presets react-app
This seems to work, plus all the CRA scripts (start, test and build) seem unaffected.
So if you need to do this, it looks like you can achieve it without having to eject. Which is a nice surprise.
The text was updated successfully, but these errors were encountered: