Using create-response-app to create a library

I am trying to create a React-Redux library, and I am trying to use create-react-app to get the boilerplate code, but it includes things like appHtml that are irrelevant in the script construct.

Is there a way to turn the created create-response-app into the library - in particular, I do n’t need to pack all the js files into one, but instead just pass them through babel and create separate files for each React Component?

+4
javascript reactjs create-react-app
source share
3 answers

I managed to create the library without extracting and using the internal dependencies of creating the application-application. I tested it with react-scripts@0.9.5 . First you need to install babel-cli :

 npm install --save-dev babel-cli 

create a .babelrc file with content:

 { "presets": ["react-app"] } 

Then add the script to package.json :

 "compile": "NODE_ENV=production babel src --out-dir lib --copy-files", 

And finally do:

 npm run compile 

This will compile all sources from the src directory to lib and simply copy the remaining files. Remember to declare the main file in package.json (for example, "main"="lib/index.js" ).

However, there is one caveat. If you use files that cannot be compiled using babel (for example, css or fonts), users of your library will need to configure the appropriate loaders (webpack).

+5
source share

this is the best i have found so far .... create-react-app for libraries https://github.com/Rubbby/create-react-library

+2
source share

Edit the following in package.json

  • name
  • description
  • scripts
  • author
  • license
  • gitRepository

and do npm publish . It will publish your library in npm

+1
source share

All Articles