Hello,
I'm trying to precompile my templates using gulp, specifically using the
gulp-nunjucks extension. The documentation is pretty insistent about using the 'nunjucks-precompile' script, but this extension just uses the precompile method. My goal is to create one "templates.js" file which I include on my page, letting me render templates normally.
First of all, I don't see how I can do this using the precompile method -- if I provide a name function which returns the same name for every file, will it somehow concatenate them into one larger file that still works? Currently, the method precompiles all of my templates into separate files, leading to an unmanageable number of files to include on my page. I tried concatenating them using gulp-concat, but that file didn't work. How do I go about folding all of my templates into one pretty pre-compiled Javascript file?
Second of all, I also want to be able to import templates from the client. There are macros in a template file which I need to render from the client, and my current way of doing that is
nunjucks.renderString("{% import 'packageForms.html' as forms %} {{ forms.packageForm('task') }}");
This worked fine when I just put the templates directly into the directory, but now that I'm precompiling I get a "Template Not Found" error when it tries to find the /templates/packageForms.html file. This makes sense because the HTML file is no longer there, replaced by a Javascript one. Should that import work correctly if I have a correctly created pre-compiled template file? I'm not sure how to get this working properly.
Thanks,
John