# Koa_typescript **Repository Path**: Tiu_G/koa_typescript ## Basic Information - **Project Name**: Koa_typescript - **Description**: Koa_typescript模板 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-07-15 - **Last Updated**: 2024-12-01 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 1.创建项目,安装依赖 ```` npm install -g typescript //安装ts //新建个工程文件夹 npm init //npm初始化 tsc --init //ts初始化 # 安装Koa npm install -save koa # 安装Koa body 解析插件 npm install -save koa-body # 安装 nodemon 监听文件修改,用于热重启项目 npm install -save nodemon # 安装Koa d.ts npm install -save @types/koa ```` # 2配置 ```` **tsconfig.json ** { "compilerOptions": { "target": "ES2016", /* 将TS编译成目标版本js 'ES3' (默认), 'ES5', 'ES2015', 'ES2016'*/ "module": "commonjs", "outDir": "./dist/", /* 编译输出文件夹 */ "rootDir": "./src/", /* 项目源码文件夹 */ "strict": true, "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true } } **nodemon.json** { "verbose": true, "ignore": [ "*.test.js", "fixtures/*" ], "execMap": { "rb": "ruby", "pde": "processing --sketch={{pwd}} --run" }, "watch": [ "src/" /* 监听的路径 */ ] } **package.json** { "name": "demo1", "version": "1.0.0", "main": "app.js", "license": "MIT", "scripts": { /* 启动的时候先编译 ts 然后再运行编译出来的文件 */ "start": "tsc --build && node ./dist/app.js", /* 启动监听器运行项目 */ "watch": "nodemon --ext js,ts --exec yarn start" }, "dependencies": { "@types/koa": "^2.11.4", "koa": "^2.13.0", "koa-body": "^4.2.0", "nodemon": "^2.0.4" } } ```` # 3.编写代码 ```` 根目录创建 ./dist ./src 两个目录 在./src中创建app.ts,就可以开始撸代码了 ```` # 4运行代码 ```` npm run start 通过监听器运行代码 npm run watch ````