create-react-app and typescript

阅读create-react-app源码时发现其官方在追加了typescript的支持,在此之前一直是第三方支持create-react-app-typescript

这里简单对比二者的区别

初始化方式

1
2
# 官方最新支持的
npx create-react-app my-app --typescript
1
2
# 第三方支持的
npx create-react-app my-app --scripts-version=react-scripts-ts

目录结构

左侧第三方,右侧官方

注意事项

微软官方认为第三方插件默认情况下做了太多的事情,所以需要修改默认设置

官方原话如下:

The TSLint configuration that react-scripts-ts sets us up with is a bit overzealous.
Let’s fix that up.

1
2
3
4
5
6
7
8
9
10
11
 {
- "extends": ["tslint:recommended", "tslint-react", "tslint-config-prettier"],
+ "extends": [],
+ "defaultSeverity": "warning",
"linterOptions": {
"exclude": [
"config/**/*.js",
"node_modules/**/*.ts"
]
}
}

Configuring TSLint is out of the scope of this starter, but you should feel free to experiment with something that works for you.

对比发现官方原生支持的并没有此类状况。

参考: