I'd like the option to import required partials automatically, rather than needing to define them globally. I've started work on this in #3, but ran into the following conundrum:
The partial references within the handlebars templates will need to be resolved, more than just when they're imported. That is to say, the following:
{{!body.hbs}}
<body>
{{> ./content}}
</body>
{{!content.hbs}}
<p>Hello, world!</p>
Will need to produce:
// This will be resolved by rollup or a plugin defined on rollup.
import './content';
import HandlebarsCompiler from 'handlebars/runtime';
const Template = HandlebarsCompiler.template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
var stack1;
return "<body>\n"
+ ((stack1 = this.invokePartial(partials['/path/to/content'],depth0,{"name":"./content","data":data,"indent":" ","helpers":helpers,"partials":partials})) != null ? stack1 : "")
+ "</body>";
},"usePartial":true,"useData":true});
export default Template;
import HandlebarsCompiler from 'handlebars/runtime';
const Template = HandlebarsCompiler.template(/* template data */);
HandlebarsCompiler.registerPartial('/path/to/content.hbs', Template);
export default Template;
Where the body.hbs
template data differs as follows:
diff --git a/a.txt b/a.txt
--- a/a.txt
+++ b/a.txt
@@ -2,6 +2,6 @@
var stack1;
return "<body>\n"
- + ((stack1 = this.invokePartial(partials['./content'],depth0,{"name":"./content","data":data,"indent":" ","helpers":helpers,"partials":partials})) != null ? stack1 : "")
+ + ((stack1 = this.invokePartial(partials['/path/to/content'],depth0,{"name":"/path/to/content","data":data,"indent":" ","helpers":helpers,"partials":partials})) != null ? stack1 : "")
+ "</body>";
},"usePartial":true,"useData":true}
This would require hooking into rollup's resolveId
options, which are not exposed in any manner, public or otherwise.