DimiMikadze / create-react-library

React NPM library starter kit based on Facebook's create react app
MIT License
602 stars 60 forks source link

How can I publish the library to be used in browser (as UMD module ?! ) #41

Closed ieugen closed 6 years ago

ieugen commented 6 years ago

Hello,

I wish to publish my library to be used in browser. How can I do that? It would be great if this was added to the documentation.

Thanks,

DimiMikadze commented 6 years ago

Hi, this library is intended to create NPM packages, ( React NPM library starter kit ) and it's definitely for browser since it's React.

Without NPM i've never tried to use library built with this starter kit, but maybe try to load React and ReactDom first and then load your bundle?

ieugen commented 6 years ago

Thanks, we chosed to use nwb. It has OOTB umd module publishing.

mwarger commented 6 years ago

@ieugen In case it's any help, you can modify the rollup config to output a UMD by adding this to the output:

...
output: [
    {
      file: pkg.main,
      format: 'umd',
      sourcemap: true,
      name: 'exampleComponent'  // this name is how the component is referenced in javascript
    },
    {
      file: pkg.module,
      format: 'es',
      sourcemap: true
    }
  ],