Skip to content

Commit b2a869e

Browse files
committed
Add template support
1 parent 9788522 commit b2a869e

File tree

156 files changed

+700
-316
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+700
-316
lines changed

docusaurus/docs/adding-typescript.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ title: Adding TypeScript
1212
To start a new Create React App project with [TypeScript](https://www.typescriptlang.org/), you can run:
1313

1414
```sh
15-
npx create-react-app my-app --typescript
15+
npx create-react-app my-app --template typescript
1616

1717
# or
1818

19-
yarn create react-app my-app --typescript
19+
yarn create react-app my-app --template typescript
2020
```
2121

2222
> If you've previously installed `create-react-app` globally via `npm install -g create-react-app`, we recommend you uninstall the package using `npm uninstall -g create-react-app` to ensure that `npx` always uses the latest version.
23+
>
24+
> Global installs of `create-react-app` are no longer supported.
2325
2426
To add [TypeScript](https://www.typescriptlang.org/) to a Create React App project, first install it:
2527

@@ -49,5 +51,4 @@ If your project is not created with TypeScript enabled, npx may be using a cache
4951

5052
If you are currently using [create-react-app-typescript](https://github.com/wmonk/create-react-app-typescript/), see [this blog post](https://vincenttunru.com/migrate-create-react-app-typescript-to-create-react-app/) for instructions on how to migrate to Create React App.
5153

52-
5354
Constant enums and namespaces are not supported, you can learn about the constraints of [using Babel with TypeScript here](https://babeljs.io/docs/en/babel-plugin-transform-typescript#caveats).

docusaurus/docs/getting-started.md

+23-3
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,33 @@ yarn create react-app my-app
6262

6363
_`yarn create` is available in Yarn 0.25+_
6464

65-
### Creating a TypeScript app
65+
### Selecting a template
6666

67-
Follow our [Adding TypeScript](adding-typescript.md) documentation to create a TypeScript app.
67+
You can now optionally start a new app from a template by appending `--template [template-name]` to the creation command.
68+
69+
If you don't select a template, we'll create your project with our base template.
70+
71+
Templates are always named in the format `cra-template-[template-name]`, however you only need to provide the `[template-name]` to the creation command.
72+
73+
```sh
74+
npx create-react-app my-app --template [template-name]
75+
```
76+
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.
78+
79+
#### Creating a TypeScript app
80+
81+
You can start a new TypeScript app using templates. To use our provided TypeScript template, append `--template typescript` to the creation command.
82+
83+
```sh
84+
npx create-react-app my-app --template typescript
85+
```
86+
87+
If you already have a project and would like to add TypeScript, see our [Adding TypeScript](adding-typescript.md) documentation.
6888

6989
### Selecting a package manager
7090

71-
When you create a new app, the CLI will use [Yarn](https://yarnpkg.com/) to install dependencies (when available). If you have Yarn installed, but would prefer to use npm, you can append --use-npm to the creation command. For example:
91+
When you create a new app, the CLI will use [Yarn](https://yarnpkg.com/) to install dependencies (when available). If you have Yarn installed, but would prefer to use npm, you can append `--use-npm` to the creation command. For example:
7292

7393
```sh
7494
npx create-react-app my-app --use-npm
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# cra-template-typescript
2+
3+
This is the official TypeScript template for [Create React App](https://github.com/facebook/create-react-app).
4+
5+
To use this template, simply add `--template typescript` when creating a new app.
6+
7+
For example:
8+
9+
```sh
10+
npx create-react-app my-app --template typescript
11+
12+
# or
13+
14+
yarn create react-app my-app --template typescript
15+
```
16+
17+
For more information, please refer to:
18+
19+
- [Getting Started](https://create-react-app.dev/docs/getting-started) – How to create a new app.
20+
- [User Guide](https://create-react-app.dev) – How to develop apps bootstrapped with Create React App.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "cra-template-typescript",
3+
"version": "1.0.0",
4+
"keywords": [
5+
"react",
6+
"create-react-app",
7+
"template",
8+
"typescript"
9+
],
10+
"description": "The base TypeScript template for Create React App.",
11+
"main": "template.json",
12+
"repository": {
13+
"type": "git",
14+
"url": "https://github.com/facebook/create-react-app.git",
15+
"directory": "packages/cra-template-typescript"
16+
},
17+
"license": "MIT",
18+
"engines": {
19+
"node": ">=8"
20+
},
21+
"bugs": {
22+
"url": "https://github.com/facebook/create-react-app/issues"
23+
},
24+
"files": [
25+
"template",
26+
"template.json"
27+
]
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"dependencies": {
3+
"@types/node": "^12.0.0",
4+
"@types/react": "^16.9.0",
5+
"@types/react-dom": "^16.9.0",
6+
"@types/jest": "^24.0.0",
7+
"typescript": "^3.6.0"
8+
}
9+
}

packages/cra-template/README.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# cra-template
2+
3+
This is the official base template for [Create React App](https://github.com/facebook/create-react-app).
4+
5+
If you don't specify a template (for example, `--template typescript`), this template will be used by default.
6+
7+
For more information, please refer to:
8+
9+
- [Getting Started](https://create-react-app.dev/docs/getting-started) – How to create a new app.
10+
- [User Guide](https://create-react-app.dev) – How to develop apps bootstrapped with Create React App.

packages/cra-template/package.json

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "cra-template",
3+
"version": "1.0.0",
4+
"keywords": [
5+
"react",
6+
"create-react-app",
7+
"template"
8+
],
9+
"description": "The base template for Create React App.",
10+
"main": "template.json",
11+
"repository": {
12+
"type": "git",
13+
"url": "https://github.com/facebook/create-react-app.git",
14+
"directory": "packages/cra-template"
15+
},
16+
"license": "MIT",
17+
"engines": {
18+
"node": ">=8"
19+
},
20+
"bugs": {
21+
"url": "https://github.com/facebook/create-react-app/issues"
22+
},
23+
"files": [
24+
"template",
25+
"template.json"
26+
]
27+
}

packages/cra-template/template.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"dependencies": {}
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
body {
2+
margin: 0;
3+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
4+
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
5+
sans-serif;
6+
-webkit-font-smoothing: antialiased;
7+
-moz-osx-font-smoothing: grayscale;
8+
}
9+
10+
code {
11+
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
12+
monospace;
13+
}

0 commit comments

Comments
 (0)