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

Library/multi-component example? #284

Closed
1 of 4 tasks
mklemme opened this issue Mar 23, 2017 · 10 comments
Closed
1 of 4 tasks

Library/multi-component example? #284

mklemme opened this issue Mar 23, 2017 · 10 comments
Labels

Comments

@mklemme
Copy link

mklemme commented Mar 23, 2017

This issue is a:

  • Bug report
  • Feature request
  • Question / support request
  • Other

I wanted to create a react component library and saw that the docs mention this is possible, but only offers react-bootstrap as an example, which doesn't have the nwb.config files.

Is there a simple example of how to get this working with multiple components in the src file? What would I have to do with the nwb.config file to get multiple components built for distribution?

@m-torin
Copy link

m-torin commented Mar 28, 2017

I made my project multi-component by looking at the Semantic UI style... https://github.com/Semantic-Org/Semantic-UI-React/blob/master/src/index.js

@mklemme
Copy link
Author

mklemme commented Mar 28, 2017

@torinagrippa thanks for the reference. Should help with the bulk export. How did you set up the compiling for multiple components? What do I have to change in the nwb.config file? https://github.com/insin/nwb/blob/master/docs/guides/ReactComponents.md#build-configuration

@hoodsy
Copy link

hoodsy commented Apr 28, 2017

@torinagrippa I'm using Aphrodite for CSS-in-JS and have had difficulties importing font files.

Have you all been able to import custom font files to use in the demo page?

@01taylop
Copy link

01taylop commented Jun 6, 2017

@mklemme Did you have any luck creating your react component library?

@mklemme
Copy link
Author

mklemme commented Jun 6, 2017

@01taylop I wasn't able to get this project working but am using https://github.com/FormidableLabs/builder-react-component

@01taylop
Copy link

01taylop commented Jun 7, 2017

Thanks, might use that for the next project.

I have found the solution in Configuration.md, you need to set the babel stage to 1 in the nwb.config.js file:

if you want to use export extensions in your app, you should set stage to 1

module.exports = {
  babel: {
    stage: 1
  }
}

@insin insin added the docs label Jun 7, 2017
@insin
Copy link
Owner

insin commented Jun 7, 2017

Should really add that to the libraries section of the component guide

@insin insin closed this as completed in 1872599 Jun 17, 2017
@TarikHuber
Copy link

Is it possible to create a library my-component where you could do something like

import { Component1 } from 'my-component/part1'
import { Component2 } from 'my-component/part2'
import Component3  from 'my-component/part3/Component3  '
import MainComponent from 'my-component'

Having everything in a single index.js makes that file huge. By slitting everything in own folders would make the usage much more structured. A great example is Material-UI

In they docu they recommend to use "folder" way of import.

In the docu:

Notice that in the above example, we used:

import RaisedButton from 'material-ui/RaisedButton';

instead of

import {RaisedButton} from 'material-ui';

This will make your build process faster and your build output smaller. For a complete mapping of Material-UI components to import, see /src/index.js inside the Material-UI npm package root directory.

@rkouye
Copy link

rkouye commented May 30, 2018

@TarikHuber did you find a way to do this?

So far I am doing
import Component1 from 'my-library/lib/Component1';
But I wish I could do
import Component1 from 'my-library/Component1';

Hi @insin, is this use case supported? Or should we copy from the lib folder after building (and update main in package.json) ?

@TarikHuber
Copy link

Hi @semako-kouye ,

Unfortunately no. I'm also still using the lib. It would be great if this would be supported. It is great for code splitting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants