usecreate-react-appIf you want to change some configurations, one way is to use
ejectDirective, but subsequent updates may not be synchronized. Another way is to usereact-app-rewiredOverwrite the corresponding configuration. This method cannot be set. A better way is to make user-defined modifications directly based on the original build script, which is convenient to synchronize subsequent updates.
create-react-appIt contains many different libraries and usesLernaManage. The relevant scripts built are mainly inreact-scriptsYes. adoptForkYou can publish your own version or synchronize the official version.
2. Modify the corresponding library
After fork, clone the corresponding library locally. Before modifying, it is recommended to create your own modification branch based on the published branch. As an example, in
/packages/react-scripts/scripts/init.jsAdd some print logs to the.
3 release package
Because it’s fork’s bag, insidepackage.jsonSome of the description information needs to be modified. At least inside
nameThe field value needs to be changed. The name of the example is changed tocustomize-react-scripts。 For other description information, judge whether it needs to be modified according to the actual situation.
npm login npm publish
For detailed description of release package, seehere 。
4 using custom packages
After publishing successfully, go to a directory and execute the following command:
npx create-react-app test-app --scripts-version customize-react-scripts
You can see the following information prompt.
After the installation is successful, you can see the previously added prompt information.