So I recently added typescript to my ExpressJS project (and it's still magic for me).
I'm trying to build an app in a /dist directory (.ts -->.js), but it doesn't generate swagger.yaml file NOR sequelize-cli folder.
Making some changes in tsconfig.json does literally nothing, which is really weird for me.
My project structure:
- 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
My package.json:
{
"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"
}
}
My tsconfig.json:
{
"compilerOptions": {
"module": "CommonJS",
"moduleResolution": "Node",
"esModuleInterop": true,
"target": "ES6",
"removeComments": true,
"rootDir": "./src",
"outDir": "./dist",
},
"include": [ "src/**/*" ],
"exclude": [ "node_modules" ]
}
I have no idea what's wrong
The TS compiler only deals with TypeScript and JavaScript files and you need some sort of bundler to handle other file types. However there is a solution which doesn't use a bundler.
In your package.json
you can specify a script, which will
dist
folder with your compiled code.dist
folder.An example script for this would be -
"start": "tsc && copyfiles -u 1 src/sequelize-cli/**/* src/swagger.yaml dist && node dist/server.js"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.