How to get string instead of function?
Apologies if the solution is obvious, but is there any way to import Handlebars templates as strings and not functions? I'd like to skip the cost of evaluating the function in my client-side code and also skip the ~60k increase in bundle size from bundling the Handlebars runtime. It seems it should be pretty straightforward, but no matter what options or loader combination I try I haven't been successful.
For example, if I put Hello World into my-template.hbs I'd like the following TypeScript code:
import * as template from './my-template.hbs'
console.log(template);
to produce the following JS code:
console.log("Hello World");
In WebPack you can use raw-loader to load content of file "raw-loader!./my-template.hbs"
I wish it were that simple! That was my first of many attempts. Doing so just returns the handlebars function in a string. Looking through this loader's code and comparing it to other loaders, there's no path that outputs just a pure string it looks :(
Sorry for resurrecting a dead issue, but did anyone ever figure out a way of doing this? I am trying to use Handlebars to render a template inside Vue, but it keeps just printing the function reference.
@Stmated this loader spits out template functions, and you need to run them elsewhere to actually get the string generated by the template. Example
Might need to see your code if that doesn't help!
Yeah, I know how it would usually work. I tried to solve this by using skeleton-loader and eval'ing the content given to it, to return just the resulting html, but that just spits out errors about modules not being found, etc. I guess I'll just go with pug-plain-loader instead, and get back to trying to solve it with handlebars another day.