Skip to content

Commit 29c5e55

Browse files
mrmckebiansu
andcommitted
Update template docs (#8050)
* Update template docs * Update custom-templates.md * Update custom-templates.md Co-authored-by: Ian Sutherland <[email protected]>
1 parent f6ba862 commit 29c5e55

File tree

3 files changed

+91
-2
lines changed

3 files changed

+91
-2
lines changed

CHANGELOG.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,19 @@ v3.3.0 is a minor release that adds new features, including custom templates and
44

55
### Custom Templates
66

7-
DRAFT
7+
You can now create a new app using custom templates.
8+
9+
We've published our existing templates as [`cra-template`](https://github.com/facebook/create-react-app/tree/master/packages/cra-template) and [`cra-template-typescript`](https://github.com/facebook/create-react-app/tree/master/packages/cra-template-typescript), but we expect to see many great templates from the community over the coming weeks.
10+
11+
The below command shows how you can create a new app with `cra-template-typescript`.
12+
13+
```sh
14+
npx create-react-app my-app --template typescript
15+
```
16+
17+
Note that you can omit the prefix `cra-template-` when specifying which template you would like. For TypeScript users, we're deprecating `--typescript` in favour of `--template typescript`.
18+
19+
If you don't set a template, we'll create your new app with `cra-template` - which is just a new name for our base template.
820

921
### Optional Chaining and Nullish Coalescing Operators
1022

docusaurus/docs/custom-templates.md

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
id: custom-templates
3+
title: Custom Templates
4+
---
5+
6+
> Note: this feature is available with `[email protected]` and higher.
7+
8+
Custom Templates enable you to select a template to create your project from, while still retaining all of the features of Create React App.
9+
10+
You'll notice that Custom Templates are always named in the format `cra-template-[template-name]`, however you only need to provide the `[template-name]` to the creation command.
11+
12+
### npm
13+
14+
```sh
15+
npm init react-app my-app --template [template-name]
16+
```
17+
18+
### Yarn
19+
20+
```sh
21+
yarn create react-app my-app --template [template-name]
22+
```
23+
24+
## Finding custom templates
25+
26+
We ship two templates by default:
27+
28+
- [`cra-template`](https://github.com/facebook/create-react-app/tree/master/packages/cra-template)
29+
- [`cra-template-typescript`](https://github.com/facebook/create-react-app/tree/master/packages/cra-template-typescript)
30+
31+
However, you can find many great community templates by searching for ["cra-template-\*"](https://www.npmjs.com/search?q=cra-template-*) on npm.
32+
33+
## Building a template
34+
35+
If you're interested in building a custom template, first take a look at how we've built [`cra-template`](https://github.com/facebook/create-react-app/tree/master/packages/cra-template).
36+
37+
A template must have the following structure:
38+
39+
```
40+
my-app/
41+
README.md (for npm)
42+
template.json
43+
package.json
44+
template/
45+
README.md (for projects created from this template)
46+
gitignore
47+
public/
48+
index.html
49+
src/
50+
index.js (or index.tsx)
51+
```
52+
53+
### The `template` folder
54+
55+
This folder is copied to the user's app directory as Create React App installs. During this process, the file `gitignore` is renamed to `.gitignore`.
56+
57+
You can add whatever files you want in here, but you must have at least the files specified above.
58+
59+
### The `template.json` file
60+
61+
This is where you can define dependencies (only dependencies are supported for now), as well as any custom scripts that your template relies on.
62+
63+
```json
64+
{
65+
"dependencies": {
66+
"serve": "^11.2.0"
67+
},
68+
"scripts": {
69+
"serve": "serve -s build",
70+
"build-and-serve": "npm run build && npm run serve"
71+
}
72+
}
73+
```
74+
75+
For convenience, we always replace `npm run` with `yarn` in your custom `"scripts"`, as well as in your `README` when projects are initialized with yarn.

docusaurus/docs/getting-started.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ Templates are always named in the format `cra-template-[template-name]`, however
7474
npx create-react-app my-app --template [template-name]
7575
```
7676

77-
> You can find a a list of available templates by searching for ["cra-template-\*"](https://www.npmjs.com/search?q=cra-template-*) on npm.
77+
> You can find a list of available templates by searching for ["cra-template-\*"](https://www.npmjs.com/search?q=cra-template-*) on npm.
78+
79+
Our [Custom Templates](custom-templates.md) documentation describes how you can build your own template.
7880

7981
#### Creating a TypeScript app
8082

0 commit comments

Comments
 (0)