alexlafroscia / vite-plugin-handlebars

Vite support for Handlebars
176 stars 21 forks source link

Support `.hbs` extensions for entry files #39

Open alexlafroscia opened 3 years ago

alexlafroscia commented 3 years ago

As far as I can tell, Vite makes a hard assumption that the file it starts to resolve linked files from is an HTML file. There is code I've seen internally that validates that the extension is .html.

It would be nice if we could use .hbs for these files, if we're going to have Handlebars syntax in them, just for the purposes of syntax highlighting and the like.

I'm not sure what allowing non-html files at the "top level" would look like, but it would be really nice to support!

alexlafroscia commented 3 years ago

I've been looking into this, and I don't think it's possible. Rollup doesn't seem to support changing the id for a file while transforming it, and a bunch of logic within Vite seems to require the .html extension for the entry file.

I can successfully get the .hbs file at the top level through the Handlebars transform, but something within Vite (or maybe Rollup?) chokes on it after that; presumably because it's getting the wrong extension.

Chris2011 commented 3 years ago

I now run in this problem :D. Of course I can fix it with changeing hbs from html but as you already said, it would be cool. Beside that, I didn't believe that this is possible, I googled just short and I found this: https://github.com/yohangz/rollup-plugin-hbs Could this be a solution?

alexlafroscia commented 3 years ago

Unfortunately, I don't think it is. That plugin defines a transform hook, which this plugin currently does not do, but certainly could!

I took a stab at implementing one to see if that would do the trick last week, but unfortunately it did not because I can't change the .hbs file extension to .html through the transform, and Vite is expecting that the "entry file" is an .html file (it's hard-coded in their code in some places that I've seen while looking through how Vite actually "works" under-the-hood).

It could be an issue worth raising on the Vite repo to see if we could somehow find a solution to this, though!

Chris2011 commented 3 years ago

Maybe there could be a ticket created for hbs. I dunno whether there is a ticket yet. I googled a couple of days ago and all what I found was the rollup hbs plugin. @jdf221 thx for investigating :).

Chris2011 commented 3 years ago

I saw the discussion in the vite repo. Is there anything new here? Do you think, your code is ready for a PR @jdf221 ?