-
-
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 2 commits
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 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 commentThe reason will be displayed to describe this comment to others. Learn more. Publish your fork by running |
||
```sh | ||
$ npm run 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. Is there any way to test without publishing first? My understanding is that NPM will not allow you to re-use version numbers. 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. npm link can help with that 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. create-react-app insist on downloading the custom script from NPM even after I npm link my custom scripts package. 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. @amccloud you can still init your app with the default |
||
``` | ||
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 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.