Custom create-react-app

Primer

Using the create-react-app when you want to change some configuration, one way is to use the ejectcommand, 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 .

72-fork

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.jsto add some print log.

72-modify

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 namefield 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.

72-start

After the installation is successful, you can see the prompt information added earlier.

72-success

References

Guess you like

Origin www.cnblogs.com/thyshare/p/12721470.html