Issue
I am using express and typescript. I use alot express handlebars. However, I noticed that when compiling with tsc, the views folder are not copying into the dist folder.
in the SRC directory I have the views, that contains two other directories containing hbs files:
|
└── src
└── views
└── emails
└── invitation-email.hbs
My hosting provider is configured to load the dist folder, that should contain all the folders including the views and public folder that are not copying in the DIST folder...
Here is my package json:
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "jest",
"dev": "nodemon src/server.ts",
"build": "tsc -p tsconfig.json",
"start": "npm run build && node dist/server.js",
"clean": "rimraf dist"
},
"keywords": [],
"author": "Daniel mihai",
"license": "ISC",
"dependencies": {
"@types/bcryptjs": "^2.4.6",
"@types/express": "^4.17.21",
"@types/handlebars": "^4.1.0",
"@types/mongoose": "^5.11.97",
"@types/node": "^20.10.5",
"@types/nodemailer": "^6.4.14",
"bcryptjs": "^2.4.3",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"express-handlebars": "^7.1.2",
"handlebars": "^4.7.8",
"hbs": "^4.2.0",
"mongoose": "^8.0.3",
"nodemailer": "^6.9.8",
"nodemon": "^3.0.2"
},
"devDependencies": {
"@types/jest": "^29.5.11",
"@types/supertest": "^6.0.2",
"jest": "^29.7.0",
"mongodb-memory-server": "^9.1.3",
"rimraf": "^5.0.5",
"supertest": "^6.3.3",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
}
}
My tsconfig.json :
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"strict": true,
"rootDir": "./src",
"outDir": "./dist"
},
"include": ["src/**/*"] // Adjust the 'include' pattern to match your source files
}
Solution
tsc
only builds the typescript into the dist folder.
Take a look at npm copyFiles.
Your build
command will look something like this "build": "tsc -p tsconfig.json && copyfiles src/views dist/views && copyfiles src/public dist/public"
Answered By - Trevor V
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.