-
-
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
Changes from 1 commit
90220fb
8bac1c5
aaa255d
83d092f
10ead31
c27cd91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,7 @@ You can find the most recent version of this guide [here](https://github.com/fac | |
- [Modulus](#modulus) | ||
- [Now](#now) | ||
- [Surge](#surge) | ||
- [Fork instead of eject](#fork-instead-of-eject) | ||
- [Something Missing?](#something-missing) | ||
|
||
## Updating to New Releases | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. We style it as "Create React App" throughout this guide instead of There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
|
||
### Instruction | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This subtitle can be removed |
||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Let’s say "Fork the There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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:
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I'll update in an hour |
||
|
||
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 commentThe 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". |
||
```js | ||
// /packages/react-scripts/package.json | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
{ | ||
"name": "my-react-scripts-fork", | ||
"version": "0.0.1", | ||
… | ||
} | ||
``` | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Same |
||
… | ||
{ | ||
test: /\.css$/, | ||
loader: 'style!css?modules=1!postcss' | ||
}, | ||
… | ||
``` | ||
|
||
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 commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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 I think maybe we should wait for this #765 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you know is there any difference between running I met an issue with There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. To my knowledge There's https://github.com/lerna/lerna#--force-publish-packages The normal There's also https://github.com/lerna/lerna#--only-explicit-updates Hopefully that helps. |
||
``` | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Now you can create React apps using your fork of |
||
```sh | ||
$ create-react-app my-app --scripts-version my-react-scripts-fork | ||
``` | ||
|
||
### 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 commentThe reason will be displayed to describe this comment to others. Learn more. Let's not use CRA acronym here. |
||
- It is recommended to [keep your fork synced](https://help.github.com/articles/fork-a-repo/#keep-your-fork-synced) with the upstream updates. [Backstroke](https://github.com/1egoman/backstroke) is a bot to help you with this. | ||
|
||
## Something Missing? | ||
|
||
If you have ideas for more “How To” recipes that should be on this page, [let us know](https://github.com/facebookincubator/create-react-app/issues) or [contribute some!](https://github.com/facebookincubator/create-react-app/edit/master/packages/react-scripts/template/README.md) |
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.