compile-time constants in mustache template

282 Views Asked by At

Suppose I have the following mustache template:

This is a {{#BIG_HOUSE}}really big{{\BIG_HOUSE}} house with {{NUM_WINDOWS}} windows.

and I happen to know at compile time whether BIG_HOUSE is truthy or not. How do I pass this compile-time-constant-iness through to the template compiler?

Obviously in this case it's not very interesting, but in reality the template will be a lot larger and will include several such blocks.

I am currently using mustache-loader with webpack, so any solution specific to that would be great! I also have the UglifyJSPlugin for webpack, so perhaps there is some way of using that here?

1

There are 1 best solutions below

0
simon04 On

The mustache-loader returns a function which evaluates the template when given an object of parameters. This function can be executed using the apply-loader:

require('apply-loader?{obj: {BIG_HOUSE: false}}!mustache-loader!./template.html')