NodeJS Typescript生成输出缺少某些文件

h7wcgrx3  于 2022-12-18  发布在  Node.js
关注(0)|答案(1)|浏览(140)

因此,我最近将typescript添加到了我的ExpressJS项目中(它对我来说仍然很神奇)。
我试图在/dist目录(.ts --〉.js)中构建一个应用程序,但它不会生成swagger.yaml文件或sequelize-cli文件夹。
在tsconfig.json中做一些更改实际上什么也不做,这对我来说真的很奇怪。
我的项目结构:

- dist/
  - api/**
  - classes/**
  - interfaces/**
  - sequelize/**
  - server.ts

- src/
  - api/**
  - classes/**
  - interfaces/**
  - sequelize/**
  - sequelize-cli/**
  - server.ts
  - swagger.yaml

- .dockerignore
- .env
- .gitignore
- .sequelizerc
- Dockerfile
- package-lock.json
- package.json
- tsconfig.json

* not important subdirectories & files

我的包裹

{
  "name": "random-name",
  "version": "1.0.0",
  "description": "",
  "main": "src/server.js",
  "scripts": {
    "prod": "node dist/server.js",
    "dev": "npm run build && node dist/server.js",
    "build": "tsc"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "bcrypt": "^5.1.0",
    "cookie-parser": "^1.4.6",
    "dotenv": "^16.0.3",
    "express": "^4.18.2",
    "jsonwebtoken": "^8.5.1",
    "mysql2": "^2.3.3",
    "sequelize": "^6.25.3",
    "sequelize-cli": "^6.5.2",
    "swagger-ui-express": "^4.5.0",
    "yamljs": "^0.3.0"
  },
  "devDependencies": {
    "@types/bcrypt": "^5.0.0",
    "@types/cookie-parser": "^1.4.3",
    "@types/express": "^4.17.14",
    "@types/jsonwebtoken": "^8.5.9",
    "@types/node": "^18.11.5",
    "@types/swagger-ui-express": "^4.1.3",
    "@types/yamljs": "^0.2.31",
    "nodemon": "^2.0.20",
    "ts-node": "^10.9.1",
    "typescript": "^4.8.4"
  }
}

我的tsconfig.json:

{
    "compilerOptions": {
        "module": "CommonJS",
        "moduleResolution": "Node",
        "esModuleInterop": true,
        "target": "ES6",
        "removeComments": true,
        "rootDir": "./src",
        "outDir": "./dist",
    },
    "include": [ "src/**/*" ],
    "exclude": [ "node_modules" ]
}


我不知道出了什么事

raogr8fs

raogr8fs1#

TS编译器只处理TypeScript和JavaScript文件,你需要一些捆绑器来处理其他类型的文件。但是有一个解决方案不使用捆绑器。
package.json中,您可以指定一个脚本,它将
1.运行TS编译器,用编译后的代码创建一个dist文件夹。
1.将您需要的任何额外内容复制到dist文件夹中。
1.运行代码。
此脚本的示例如下-
"start": "tsc && copyfiles -u 1 src/sequelize-cli/**/* src/swagger.yaml dist && node dist/server.js"

相关问题