I'm currently developing a serverless project which renders some HTML (.hbs templates) with NestJS and Handlebars.
nest build && sls offline start
, I can test my app endpoints in offline mode with postman => the templates are rendered perfectly.stop/restart
the offline server, my template changes are not taking in account when I test my endpoints (it is like my template are compiled only once).stop/restart
the offline server, the compiled files seem to be overrided as expected and I can see the new CSS in the rendered templates.Currently, I have to delete the .build/ folder and then stop/restart
the offline server to see my template changes in the rendered HTML when I test my endpoints...
I would like my compiled templates to be at least updated when I just stop/restart
the offline server.
And the best solution would be to update the compiled templates "in watch mode" but I've read somewhere that templates are only compiled once when the server starts (https://github.com/nest-modules/mailer/issues/42)
Here is my nest-cli.json conf:
{
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"assets": ["**/*.hbs"],
"watchAssets": true
}
}
Maybe it's not the best solution, but I solved similar problem this way: I wrote gulp task, which watches .hbs files and imitates change of main.ts file.
function watchHandlebars() {
watch('src/views/**/*.hbs').on('all', () => {
console.log('Restarting Nest');
const path = './src/main.ts';
fs.utimesSync(path, new Date(), new Date());
});
}