Fork and install Create React App without publishing on NPM

889 Views Asked by At

I would like to fork Facebook's Create React Repo and use it as a dependency instead of their own react-scripts. All tutorials on the subject publish the forked repo to NPM to install via the normal way. However, my client would prefer to not do that as both the forked Create React App and my React App repositories are hosted in the same Azure workspace.

I know CRA is a monorepo and uses Lerna. Does that make it possible?

2

There are 2 best solutions below

0
Kamil Kulach On

You could upload the package to a online git repository like GitHub. It can even be private if you want. The command to install it would then be: npm install --save-dev github:username/repo-name

If you're gonna make the repo private then you need to have SSH keys setup on GitHub and on all machines on which you will be installing the dependency on.

You could also install the dependency as a path if it's on the same file system but I have bad experiences with that so I don't recommend it.

0
Marouane Fazouane On

I've personally done that at a previous organisation. We copied any package that we forked, when heavy changes were necessary, inside our monorepo. Lerna (or yarn, or what ever) takes care of the rest.

If you have a lerna monorepo, you'd take the content of https://github.com/facebook/create-react-app/tree/master/packages/react-scripts into your monorepo, in say: packages/custom-react-scripts and change the name of the copied package in the package.json

If you'd like to rename react-scripts binary into custom-react-scripts you could do that as well via the "bin" configuration inside the copied package.json

All the renaming steps are of course optional, but it helps to know that you're not using the official tool.