-
-
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 all 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) | ||
- [Forking as Alternative to Ejecting](#forking-as-alternative-to-ejecting) | ||
- [Something Missing?](#something-missing) | ||
|
||
## Updating to New Releases | ||
|
@@ -936,6 +937,53 @@ 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). | ||
|
||
## Forking as Alternative to Ejecting | ||
You can fork `react-scripts`, publish your fork, and then use it with Create React App. | ||
|
||
Pros: | ||
- You can customize your setup (eg: add CSS Modules, PostCSS plugins, decorators, etc…) | ||
- 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. | ||
|
||
First, fork repository [`create-react-app`](https://github.com/facebookincubator/create-react-app) repository. | ||
|
||
Next, change the name of `react-scripts` package to the name you chose for your fork, and also reset its version. It is recommended to use [scoped package](https://docs.npmjs.com/misc/scope), ie: `@yourcompany/react-scripts`. | ||
### /packages/react-scripts/package.json | ||
```js | ||
{ | ||
"name": "@yourcompany/react-scripts", | ||
"version": "0.0.1", | ||
… | ||
} | ||
``` | ||
|
||
Now make your changes inside `react-scripts` package. For example, add CSS Modules: | ||
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. At this point To be more clear on this line we should say "Now make changes inside your renamed 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. Wait... I tested and renaming Should we not rename 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 that is correct. So far I think we should only change the name in |
||
### /packages/react-scripts/config/webpack.config.dev.js | ||
```js | ||
… | ||
{ | ||
test: /\.css$/, | ||
loader: 'style!css?modules=1!postcss' | ||
}, | ||
… | ||
``` | ||
|
||
Then, publish your fork by running `npm run publish` in the root of the forked repository. | ||
```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. | ||
|
||
Now you can use your customized setup with `create react app`: | ||
```sh | ||
$ create-react-app my-app --scripts-version @yourcompany/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 Create React App, with all configurations and scripts. You only need to change and publish this package, not the whole repo. | ||
|
||
## 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.
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.