-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document forking react-scripts instead of ejecting #779
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
4: [Publish](https://docs.npmjs.com/getting-started/publishing-npm-packages) your customized `react-scripts` package to npm. Remember to cd into `/packages/react-scripts/` before you publish. | ||
```sh | ||
$ cd packages/react-scripts | ||
$ npm publish |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to follow your instructions, but this will not publish a working react-scripts
package. The package needs to be published with create-react-app
's npm script npm run publish
, as this will do some cleanup tasks before publishing react-scripts
to npm. Check this out for more info: https://github.com/facebookincubator/create-react-app/blob/master/CONTRIBUTING.md#cutting-a-release
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh thank you a lot. I didn't know that. I don't know why it works in my case.. I'll update the above step
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh @Mattii I think it is because I commented out those "remove-on-publish" block with this suggestion #682 (comment)..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated it! Thank you. However, I don't know should we say something about commenting those "remove-on-publish" block.. it won't affect the process, but it seems some people use npm link
instead of publish the package.
I think maybe we should wait for this #765
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, commenting out these lines helped me to fix it in the first place :)
I didn't know about #765, but getting rid of this remove-on-publish
hook seems to be the best idea, otherwise npm link
only works with this commenting-hack.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know is there any difference between running npm publish in react-scripts
vs npm run publish in create-react-apps
, except to remove remove-on-publish
block?
I met an issue with npm run publish
: when I pull new update from upstream, and there are some updates in other packages than react-scripts
(babel-preset-react-app
for example), it ask me to publish them too, so I cannot publish my react-scripts
. Is there a way to run npm run publish
but skip other packages?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To my knowledge --scope
is only run run/exec.
There's https://github.com/lerna/lerna#--force-publish-packages --force-publish
for a specific package I believe (which could be renamed to be scope as a future thing).
The normal lerna publish
runs a git diff
so if anything changes it will try to update any packages that have changed.
There's also https://github.com/lerna/lerna#--only-explicit-updates --no-explicit-updates
to only make a new version for the actual packages that have changed (takes adv of ^) but wouldn't make sense for a major version bump.
Hopefully that helps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job. Left a few comments. We also need to figure out how to avoid publishing any other packages.
@@ -936,6 +937,50 @@ Install the Surge CLI if you haven't already by running `npm install -g surge`. | |||
|
|||
Note that in order to support routers that use html5 `pushState` API, you may want to rename the `index.html` in your build folder to `200.html` before deploying to Surge. This [ensures that every URL falls back to that file](https://surge.sh/help/adding-a-200-page-for-client-side-routing). | |||
|
|||
## Fork instead of eject |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let’s call this Forking as Alternative to Ejecting
, with capitalized words.
@@ -936,6 +937,50 @@ Install the Surge CLI if you haven't already by running `npm install -g surge`. | |||
|
|||
Note that in order to support routers that use html5 `pushState` API, you may want to rename the `index.html` in your build folder to `200.html` before deploying to Surge. This [ensures that every URL falls back to that file](https://surge.sh/help/adding-a-200-page-for-client-side-routing). | |||
|
|||
## Fork instead of eject | |||
|
|||
If you want to customize the default configuration slightly (e.g. add CSS Modules, SASS, decorators…), while still having all future updates and a one dependency, you can fork this repo and create your own configuration of `react-scripts` and use it with `create-react-app`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We style it as "Create React App" throughout this guide instead of create-react-app
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to explain the tradeoffs here. What are the benefits and downsides of this approach?
|
||
If you want to customize the default configuration slightly (e.g. add CSS Modules, SASS, decorators…), while still having all future updates and a one dependency, you can fork this repo and create your own configuration of `react-scripts` and use it with `create-react-app`. | ||
|
||
### Instruction |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This subtitle can be removed
|
||
### Instruction | ||
|
||
1: Fork [create-react-app repo](https://github.com/facebookincubator/create-react-app). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let’s say "Fork the create-react-app
repository"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let’s use "1. " instead of "1: "
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry but I don't know how to make it works with code block in numbered list. The item after the code block is reset to 1:
- Some text
some code
- Another text
Can you suggest a solution? I use "1:" because I don't know how to use "1."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let’s remove the numbers altogether then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I'll update in an hour
|
||
1: Fork [create-react-app repo](https://github.com/facebookincubator/create-react-app). | ||
|
||
2: Change the name of `react-scripts` package to your new one, and also reset its version. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let’s say "to the name you chose for your fork" instead of "to your new one".
|
||
2: Change the name of `react-scripts` package to your new one, and also reset its version. | ||
```js | ||
// /packages/react-scripts/package.json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's replace this comment with a small header, just like in all examples above.
|
||
3: Make your changes inside `react-scripts` package. For example, add CSS Modules: | ||
```js | ||
// /packages/react-scripts/config/webpack.config.dev.js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
… | ||
``` | ||
|
||
4: Publish your customized `react-scripts` package with `create-react-app`'s npm script `npm run publish`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Publish your fork by running npm run publish
in the root of the forked repository.
``` | ||
It is a long process. At the end, you will be asked to update the version. | ||
|
||
5: Now you can use your customized setup with `create react app`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now you can create React apps using your fork of react-scripts
:
``` | ||
|
||
### Note | ||
- [create-react-app](https://github.com/facebookincubator/create-react-app) is a [monorepo](https://github.com/babel/babel/blob/master/doc/design/monorepo.md) that contains `react-scripts` package. This is the heart of CRA, with all configurations and scripts. You only need to change and publish this package, not the whole repo. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not use CRA acronym here.
@gaearon thank you a lot. I updated the Readme as you suggested. However, there is 1 thing I can't, please see my comment (#779 (comment)) above |
Hi @gaearon , I have updated the README to not using numbered list at all. So far, we have 2 issues:
|
@dvkndn |
regarding 1. @dvkndn Did you see my comment? #779 (comment) |
@eXtreme I myself use that solution (you also comment out those remove-on-publish block, right?), and I think many people also do that. However, it is currently suggested that we use "npm run publish" script from root #779 (comment).. Anyway, it seems we should note that it is suggested to run "npm publish --access public" first? @hzoo yes thank you I saw your comment.
I'm trying |
@hzoo it seems
|
- You still have all Create React App features and updates | ||
|
||
Cons: | ||
- You need to maintain your fork, [make sure it is synced](https://help.github.com/articles/fork-a-repo/#keep-your-fork-synced) with the upstream to have all updates. [Backstroke](https://github.com/1egoman/backstroke) is a bot that can help you with this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be worth linking to this comment explaining that the "classic" webhook method should be used if one wants Backstroke to assist in keeping the fork synced.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per backstrokeapp/server#52:
the "classic" web hook method should no longer be required.
I have backstroke setup using the standard method...
Will let you know how it goes when something is pushed to the upstream 📦
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have been successfully merging commits with @1egoman's backstroke bot for the last 4 or 5 commits. It has been working beautifully.
Is there something that needs to be done to bring this up to date? Thanks! |
@ervoiox I'm sorry it's been a long time :( I don't remember the exact commands now. But I can sure that I don't need to have a paid account. I will do again and will update with detailed information @gaearon yes there are works that need to be done to update this (actually, the update instruction will be simpler than the original one, and less issues to be mentioned) However, I can't find time until 1 March. So if anyone have time and want to take this I'd be very glad to help. If not, I will update this in March |
Thanks, I think it's fine to land this in March. Advanced users can find it here as a work in progress anyway. |
Just a heads up we released 0.9.4 with a few improvements for people who fork We care about experience of forkers, and if there's more things we should fix, please file issues. The only gotcha right now is that we're releasing from |
Is there a way forkers are able to easily tell which branch you are releasing from, so as to keep our forks as close to the upstream releases as possible? |
The easiest way would be to look at https://github.com/facebookincubator/create-react-app/releases, which specifies what branch it was cut from. Maybe we could change the default branch on the repo to 0.9.x for now, @gaearon? In the future we might want to keep Also, when we cut 0.10 we will be releasing from |
Doh!... |
Hi guys, I'm sorry but can someone take over this PR? I have no time recently nor in the near future to handle this :( |
We'll get it taken care of. Thanks for letting us know! |
how about using For example, I've been using |
|
In the end I went with #3710 instead, but thanks for your effort! |
I follow @shubheksha instruction and rewrite it as a section in User Guide. I hope it can help.
Because I didn't see anyone claim to work on this yet, so I want to start a PR and we can discuss more. In case @zperrault or anyone have worked on this already, I am totally ok to close my PR.
To be honest, I know I don't have much experience writing docs but I am very active and have much time to update my PR to be better/more useful in case anyone have any suggestion.
Related issue: #682
UPDATE:
A summary of current things that need to do:
react-scripts
package name (in itspackage.json
) (prefer scoped)npm run publish
from root