Closed
Description
It is not common knowledge that you can fork react-scripts
, publish your fork, and then do create-react-app my-app --scripts-version my-react-scripts-fork
.
This can be useful for customized setups, especially if you want to merge upstream updates once in a while. And with something like https://github.com/1egoman/backstroke, it might not even be painful!
We should document this. Help welcome!
Activity
thangngoc89 commentedon Sep 19, 2016
I tried this before. (0.2 maybe). But the global cli doesn't install the custom script. Was it fix?
sloanelybutsurely commentedon Sep 19, 2016
We are going to be forking react-scripts and attempting to move our build process over to it @trunkclub. I'll talk to the team but I think we could write documentation as we go through the process.
gaearon commentedon Sep 19, 2016
There was a bug but should be fine with 0.4.3.
leftdevel commentedon Sep 19, 2016
This is supper awesome (...if I understood correctly), Thank you! I'm loving create-react-app, but in the current state it felt like you either embrace it as it is (minimal), or move away. And "Eject" makes you feel like you're being ungrateful with the maintainers.
Now with this approach, and in my company, I can be the one maintaining the custom scripts while still keeping my teammates away from the struggle of battling configuration files.
For instance, I'd just add less-css support, and still benefit from the core create-react-app features and updates.
kirkaustin commentedon Sep 19, 2016
I just run a short custom script after create-react-app does its thing so that I can support CSSModules. All it does is alter two lines in the webpack config scripts (css loader delacarations).
Seemed like overkill to fork and publish, but maybe that's the way to go?
thangngoc89 commentedon Sep 19, 2016
@kirkaustin you don't need to publish it. You can install it directly from github
kirkaustin commentedon Sep 19, 2016
@thangngoc89 Not sure I understand. At my company we have an enterprise GitHub account. Are you suggesting that I can have my fork pulled from there?
thangngoc89 commentedon Sep 19, 2016
You're using npm to install dependencies right? You can do this
npm install git+ssh://git@github.com/your-company/react-scripts-fork
. You don't need to publish the scripts to npm and then install it.kirkaustin commentedon Sep 19, 2016
Great, thanks!
dpoineau commentedon Sep 21, 2016
Just curious if anyone has gotten a forked version of react-scripts via direct-from-github npm install working with the most recent
create-react-app
repository code? @thangngoc89With the switch by
create-react-app
to usinglerna
and as a resultreact-scripts
moving into thepackages/react-scripts
subdirectory, it doesn't seem possible to install a forkedreact-scripts
directly from github any longer (since npm cannot install from a github repo subdirectory), or am I missing something?Previously forking the entire repo (and referencing via github url) worked because
react-scripts
was the package specified in the repo's rootpackage.json
, but that's no longer the case it seems.So is publishing a custom npm package then the only way to take advantage of this approach?
dpoineau commentedon Sep 22, 2016
So for now I went down the path of using a custom published npm package (like
react-scripts-custom-whatever
), but it still seems like there's at least one issue that prevents this from working which is that thereact-scripts
package name is hardcoded in at least one spot, which won't work if you're using a custom forked package: https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/scripts/init.js#L17The end result for me is that
create-react-app
fails at executing theinit
script. Has anyone been successful with this approach with the most recent version ofreact-scripts
(0.4.3), and I'm just doing something wrong?Edit: after looking at how
e2e.sh
runs its--scripts-version react-scripts-fork
test successfully, it looks like the solution used in that fork was to just change the hardcoded package name in the line I referenced above in the fork to be the forked package name.Last edit: Here are all the steps I used to get a custom fork working in case anyone else gets as stuck as I did 😃
create-react-app
repo and cloned it locallypackages/react-scripts/package.json
to be a new custom namepackages/react-scripts/scripts/init.js#L17
to match the new package name I chosecd packages/react-scripts
followed by annpm publish
which published successfullycreate-react-app test-app --scripts-version react-scripts-my-custom-package
working as expectedgaearon commentedon Sep 22, 2016
PR to fix this would be welcome. 😉
ForbesLindesay commentedon Sep 22, 2016
I'm actually in favour of (maybe) just telling people to fork the entire monorepo and publish
create-whatever-app
andwhatever-scripts
. It would be good if you didn't have to changereact-scripts
andcreate-react-app
strings in 100 places as your first change though. I would suggest putting both of these strings in some kind ofnames.js
package in each project. That way there would be just two places it would need changing.I wonder if we should suggest people use code to generate their fork, rather than forking by hand. e.g. they could write code like
overwrite webpack.config.js with this file
. That way updating the fork would just mean re-running the code to generate the fork against the latest version of create-react-app.Alternatively, should we just encourage people to hard-fork once create-react-app is sufficiently stable?
89 remaining items
cliff76 commentedon Sep 13, 2018
Is this still a viable solution/alternative to eject? How would I add a fork of react-scripts to an existing project created with CRA? The command line doesn't seem to update/overwrite configs in an existing project. Also, when starting anew I'm also getting
Error: Cannot find module 'react-dev-utils/browsersHelper
jimthedev commentedon Sep 13, 2018
I got it working. I had to publish forks of each package and had to update all internal references to point at my packages. It’s a pain but I’m just maintaining it until 2.0 drops officially. Unfortunately it has enough custom parts I cannot publish publicly but could contribute to your fork if you have a place you want to work out of.
cliff76 commentedon Sep 13, 2018
Ouch! I see. Is there any way to update an existing project with a fork? We just started a project a couple of weeks ago via CRA and I need to make the smallest tweak to the webpack configs. I feel like I'm firing up a 747 just to visit my next door neighbor with this approach but I'm doing what I can to make things run.
cliff76 commentedon Sep 13, 2018
Also, does each fork need to have its package name updated to be different from the official repo?
jimthedev commentedon Sep 13, 2018
cliff76 commentedon Sep 13, 2018
I saw this earlier and lost the link! Does it actually work? I'll have to give it a shot. Thanks!
cliff76 commentedon Sep 14, 2018
By the way, that works like a charm, thanks!
cweekly commentedon Oct 25, 2018
I agree react-app-rewired was a great solution before CRA2. But CRA2 uses webpack 4, which breaks most plugins. Also its maintainer is apparently retiring[1], so this remains a thorny problem.
ubbcou commentedon Oct 27, 2018
It seems that I have some trouble.
I forked thie repo and now its address is https://github.com/ubbcou/create-react-app。The directory of
react-scripts
is/packages/react-scripts
。I want to use customized
react-scripts
(without publish in npm), but how can I install/packages/react-scripts
?I only know that npm can install a repository like this:
npm install --save https://github.com/ubbcou/create-react-app
, and it can't do like thisnpm install --save https://github.com/ubbcou/create-react-app/packages/react-scripts
.what should I do???
uqee commentedon Oct 27, 2018
@ubbcou publish it as a scoped package, like
@ubbcou/react-scripts
ubbcou commentedon Oct 27, 2018
@uqee
Thank you :)
So.... if I have two or more different configurations, I should publish multiple
@ubbcou/react-scripts-whatever
?react-scripts
packages storybookjs/storybook#4681hisapy commentedon Nov 21, 2018
I tried to use a fork of react-scripts with
yarn link
butyarn build
outputs to node_modules/create-react-app/build instead of MY_CURRENT_PROJECT/build. Are there any known problems that prevent using react-scripts fromyarn link
?hisapy commentedon Nov 25, 2018
Well, after diving into the code, I noticed that there paths.js module that exports different path values based on some assumptions, one of them being published, for which it tries to evaluate if the app's node_modules contains the react-scripts package, but apparently this doesn't work with symlinks created with
yarn link
.So what I've done to avoid publishing to npm each time I wanted to try something in my app, was to install my custom react-scripts from my file system with the following command:
yarn add file:/Users/hisa/workspace/create-react-app/packages/react-scripts/
This works, but the downside is that you have to run the command each time you make a modification of the your custom react-scripts. It would be awesome if we could use
yarn link
instead.