My nodejs based application uses Pug for rendering; specifically, i set the view engine and then set the view directory (which lives inside of the src directory that all other source lives in.
app.set('view engine', 'pug');
app.set('views', __dirname + '/views');
[...]
res.render('login')
This works correctly for the development version, which simply runs and interprets the typescript file that the above code is in. However, I would like to compile to javascript in production, and have the following (seemingly standard) typescript configuration:
{
"compilerOptions": {
"target": "esnext",
"module": "CommonJS",
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"outDir":"./dist",
"rootDir": "./src"
},
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Recommended",
"files": ["src/index.ts"],
}
Which reflects the directory structure of my code:
![the directory structure of my source code.](https://i.stack.imgur.com/DbMgt.png)
Unfortunately, this fails to work when the application is compiled and ruins index.js; it cannot find the .pug files in /dist/views: Error: Failed to lookup view "posts" in views directory "/app/dist/views"
I understand the error message, but not how to fix the problem. Should I be copying the templates to that folder as part of the build process? Should I be invoking them in another way that the compiler can 'understand' and include? Is compiling typescript to javascript simply an obsolete build step entirely?