I ve been trying to use handlebars in my Typescript node.js project by importing it through the readFileSync fs method, however when the project is transpiled into Javascript the .hbs file does not appear in the dist folder and the code can not find the handlebars template
I have been importing the handlebars template in a .ts file
import { handlebarsData } from "./Types/HandlebarsData";
import { readFileSync, writeFileSync } from "fs";
import Handlebars from "handlebars";
const newFile = (data: handlebarsData) = {
const template = readFileSync("./template.hbs");
const compiledTemplate = Handlebars.compile(template);
const renderedTemplate = compiledTemplate(data);
writeFileSync(`${data.name}.html`, renderedTemplate);
};
export default newClass;
And I have .hbs files in my include in the tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es6",
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist"
},
"lib": ["es2015"],
"include": ["src", "src/**/*.hbs"],
"exclude": ["node_modules"]
}
However it is not being added to the dist folder on transpile, causing the read file sync to fail
I do not have any dependencies that remove files. My only dependencies are typescript, handlebars, and ts-node.
Thanks so much for the help!