Will Parcel handle imported handlebars templates out-of-the-box?
What file extension do handlebar template files use?
@davidnagli They are .hbs
by convention, I have also seen .handlebars
.
Curious how this would work. Is the intent to be able to import the "compiled" hbs template, which is then used in code with data?
Yeah - that is how it works in the webpack loader.
You import
the handlebars file (e.g. import templ from '../templates/my_template.hbs'
). This doesn't import the handlebars template - it compiles to a template function, and then you can use this right in your code, e.g. const html = templ({name: "Bob Smith"})
.
I recently made a plugin to address the lack of support for handlebars templates. https://www.npmjs.com/package/parcel-plugin-handlebars
I would love to contribute to the parcel bundler itself, If the need arises to include built in support of handlebars in parcel.
@TheBlackBolt awesome! Feel free to add the plugin to https://github.com/parcel-bundler/awesome-parcel for others to discover.
Most helpful comment
Yeah - that is how it works in the webpack loader.
You
import
the handlebars file (e.g.import templ from '../templates/my_template.hbs'
). This doesn't import the handlebars template - it compiles to a template function, and then you can use this right in your code, e.g.const html = templ({name: "Bob Smith"})
.