Primer
Using the create-react-app when you want to change some configuration, one way is to use the eject
command, but it might not be synchronized subsequent updates. Another way is to use react-app-rewired to overwrite the corresponding configuration, this method can't still be set. A better way is to make custom modifications directly based on the original build script, and it is convenient to synchronize subsequent updates.
Introduction
The create-react-app contains multiple different libraries that are managed using Lerna . The relevant scripts built are mainly in react-scripts . Publish your own version through Fork , and you can also synchronize the official version.
operating
1 Fork
Log in to your GitHub account, Fork create-react-app . See Fork a repo for a more detailed explanation .
2 Modify the corresponding library
After the fork, clone the corresponding library to the local. Before modification, it is recommended to create an own modification branch based on the published branch. The following As an example, /packages/react-scripts/scripts/init.js
to add some print log.
3 Release package
Because it is a package from Fork, some description information of package.json in it needs to be modified. At least inside the name
field value needs to be changed, the name was changed to the example of the Customize-REACT-scripts . For other description information, determine whether it needs to be modified according to the actual situation.
npm login
npm publish
Release package details see here .
4 Use custom packages
After successful publishing, go to a directory and execute the following command:
npx create-react-app test-app --scripts-version customize-react-scripts
You can see the information prompt below.
After the installation is successful, you can see the prompt information added earlier.