codetalks-new / notes

About me
4 stars 0 forks source link

React(TypeScript)入门 #20

Open codetalks-new opened 5 years ago

codetalks-new commented 5 years ago

创建项目配置环境

  1. yarn create react-app learn-react --typescript 项目创建完成之后,显示直接依赖如下:
info Direct dependencies
├─ @types/jest@24.0.18
├─ @types/node@12.7.2
├─ @types/react-dom@16.9.0
├─ @types/react@16.9.2
├─ react-dom@16.9.0
├─ react-scripts@3.1.1
├─ react@16.9.0
└─ typescript@3.6.2

然后是一些总结性的信息:

✨  Done in 30.76s.
We detected TypeScript in your project (src/App.test.tsx) and created a tsconfig.json file for you.

Your tsconfig.json has been populated with default values.

Initialized a git repository.

Success! Created learn-react at /Users/banxi/Workspace/learn-react
Inside that directory, you can run several commands:

  yarn start
    Starts the development server.

  yarn build
    Bundles the app into static files for production.

  yarn test
    Starts the test runner.

  yarn eject
    Removes this tool and copies build dependencies, configuration files
    and scripts into the app directory. If you do this, you can’t go back!

We suggest that you begin by typing:

  cd learn-react
  yarn start

Happy hacking!
✨  Done in 89.60s.
  1. tsconfig.json
{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react"
  },
  "include": [
    "src"
  ]
}
  1. package.json
{
  "name": "learn-react",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@types/jest": "24.0.18",
    "@types/node": "12.7.2",
    "@types/react": "16.9.2",
    "@types/react-dom": "16.9.0",
    "react": "^16.9.0",
    "react-dom": "^16.9.0",
    "react-scripts": "3.1.1",
    "typescript": "3.6.2"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

安装 Chrome 扩展: React Developer Tool