Web and Node environment configuration TypeScript

0.302字数 94阅读 33


  1. install
npm init 
npm install -g typescript
tsc -init
  1. Add outDir and include to the file tsconfig.json file
  "compilerOptions": {
   "outDir": "./dist",
  "include": [
  1. Create a new index.ts the src directory, and write the

4.Directory to execute tsc to generate dist files, and then execute node ./dist/index.js

node ./dist/index.js

export 666, stage comletion

  1. Configure automatic restart
npm install --save nodemon

Create a new nodemon.json in the root directory,copy the content

    "ignore": [
    "watch": [
    "exec": "npm start",
    "ext": "ts"
  1. package.json, Add start two lines of command
"scripts": {
    "start": "tsc && NODE_ENV=development node ./dist/index.js ",
    "dev": "./node_modules/nodemon/bin/nodemon.js"
  1. Start, complete full configuration
npm run dev


  • Configuring your own webpack is very troblesome ,With react cli。
create-react-app my-app --scripts-version=react-scripts-ts
cd my-app
npm run start  


the environment configuration for TypeScript write games is complete。