CLI for creating reusable, modern React libraries using Rollup and create-react-app.
commonjs
and es
module formatsThis package requires node >= 10
.
npm install -g create-react-library
npx create-react-library
(npx comes with npm 5.2+ and higher, see instructions for older npm versions)
create-react-library
Answer some basic prompts about your module, and then the CLI will perform the following steps:
At this point, your new module should resemble this screenshot and is all setup for local development.
Local development is broken into two parts (ideally using two tabs).
First, run rollup to watch your src/
module and automatically recompile it into dist/
whenever you make changes.
npm start # runs rollup with watch flag
The second part will be running the example/
create-react-app that's linked to the local version of your module.
# (in another tab)
cd example
npm start # runs create-react-app dev server
Now, anytime you make a change to your library in src/
or to the example app's example/src
, create-react-app
will live-reload your local dev server so you can iterate on your component in real-time.
npm publish
This builds commonjs
and es
versions of your module to dist/
and then publishes your module to npm
.
Make sure that any npm modules you want as peer dependencies are properly marked as peerDependencies
in package.json
. The rollup config will automatically recognize them as peers and not try to bundle them in your module.
npm run deploy
This creates a production build of the example create-react-app
that showcases your library and then runs gh-pages
to deploy the resulting bundle.
If you use react-hooks in your project, when you debug your example you may run into an exception Invalid Hook Call Warning. This issue explains the reason, your lib and example use a different instance, one solution is rewrite the react
path in your example's package.json
to 'file:../node_modules/react' or 'link:../node_modules/react'.
Here is a branch which demonstrates how to use multiple named exports. The module in this branch exports two components, Foo
and Bar
, and shows how to use them from the example app.
Here is a branch which demonstrates how to make use of a relatively complicated peer dependency, material-ui. It shows the power of rollup-plugin-peer-deps-external which makes it a breeze to create reusable modules that include complicated material-ui subcomponents without having them bundled as a part of your module.
The CLI is based on this boilerplate, which you can optionally read about here.
Here are some example libraries that have been bootstrapped with create-react-library
.
Want to see a more completed list? Check out Made with CRL.
Want to add yours to the list? Submit an PR at the Made with CRL repository.
My open source efforts are now focused on Saasify, and I am not able to invest a significant amount of time into maintaining CRL anymore. I am looking for volunteers who would like to become active maintainers on the project. If you are interested, please shoot me a note.
MIT © Travis Fischer
Support my OSS work by following me on twitter
创建新的react应用时(npx create-react-app my-app)报错 PS D:\WorkSpace\codeFiles> npx create-react-app my-app You are running `create-react-app` 4.0.3, which is behind the latest release (5.0.1). We no longer
React中使用create-react-app以及antd页面基本搭建 React设置antd3x自定义主题,TypeError: this.getOptions is not a function的解决方法 react-app-rewired antd-在 create-react-app 中使用 yarn create react-app xxxx --template typescript
在package.json中添加 "homepage": "." 完整的 { "name": "portal", "version": "0.1.0", "private": true, "dependencies": { "@testing-library/jest-dom": "^5.16.4", "@testing-library/react": "^13
一、先抛问题 许多刚开始接触create-react-app框架的同学,不免都会有个疑问:如何在不执行eject操作的同时,修改create-react-app的配置。今天胡哥就来带大家一起来看看这个问题~ 二、为啥不建议执行eject 1. 执行eject产生了什么变化? create-react-app框架本身将webpack、babel的相关配置封装在了react-scripts中, 执行y
想要修改create-react-app的某些配置,有时候不想使用reject的办法,可以使用config-overrides.js的方式来解决,首先安装react-app-rewired、customize-cra。 一、引入react-app-rewired customize-cra (1)安装模块 npm install react-app-rewired customize-cra --
使用create-react-app方式引入antd样式 发布时间:2018-08-20 13:58, 浏览次数:581 , 标签: create react app antd 今天试了一下使用create-react-app快速构建React 的环境下引用antd,but! 引入后发现我的antd的样式压根就没有引入, 所以上网搜索了一下 点此进入快速构建React开发环境 以下给出的解释: 由
截至到 2022年6月16日为止,CRA5 已经发布,然而 craco 的仍然未发布支持 CRA5 的稳定版本,并且官方似乎不像把精力放在 craco 上,因此推荐改用 react-app-rewired。另外 antd 对于 react18 的支持怎么样笔者没有测试过,建议去 Github 看看 issue 或者 raodmap。综上所述,文章中出现的部分第三方库已经过时,文章内容仅供参考。 谁
React create-react-app 全局安装create-react-app $ npm install -g create-react-app 创建一个项目 $ create-react-app your-app 注意命名方式 Creating a new React app in /dir/your-app. Installing packages. This might take
create-react-app项目配置 一、react-app-rewired && customize-cra react-app-rewired是react社区开源的一个修改CRA配置的工具,例如扩展Create React App的Webpack配置,而customize-cra提供了一组用于自定义利用react-app-rewired核心功能的Create React App v2配置,
Q1. yarn build打包生成的文件直接点击index.html报错,打不开,导致的问题是yarn build打包生成的文件部署到服务器时只能在服务器根目录,如果在其他文件夹里面会报错 A1: 默认情况下,index.html中引入js和css的方式是,需要在本地启一个服务器才行,即在打包文件根目录下打开命令行,输入http-server,即可通过localhost:8080来访问到项目。
Create React App 不用配置就可以创建 React App。 全局安装: npm install -g create-react-app 创建 App: create-react-app my-appcd my-app/ 启动 npm: npm start 打开 http://localhost:3000/ 查看你的 App。 如果你准备将其部署到生产环境,只需创建一个压缩包,并且运行 npm run build。
react-native-create-bridge Bridging native modules & UI components made easy! If you're a JavaScript developer writing your first lines of native code or a more experienced developer looking to elimin
Create React Native App The fastest way to create universal React Native apps npx create-react-native-app Once you're up and running with Create React Native App, visit this tutorial for more informat
Create React Redux App Structure Create React + Redux app structure with build configurations. What can I find here? Express, Cors React + Redux, ES6, async/await Web Components (Custom Elements) inte
create-react-app React Project with Node Express Backend Example on using create-react-app with a Node Express Backend Usage Install nodemon globally npm i nodemon -g Install server and client depende
问题如下: 想要在React 项目执行yarn build 时, 给index.html 增加后缀 没有使用react-eject, 使用的是crao 替代, 但是craco.config.js 配置 HtmlWebpackPlugin不生效。 craco.config.js 配置如下: package.json 部分组件版本如下: 执行yarn build 打包后,配置无效, 请教各位大佬们了