feature(precompile): allow for precompilation #27
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've added an option to allow precompilation. Simply setting this to true will create a file with the precompilation function in it. Specifying a string on the other hand considers this a lodash template which is compiled using gutil.template. This allows for things like
opts.precompile = "module.exports = <%= template %>"
to create modules from templates. Alternatively some magic can be done with gulp-concat to let users create a single module from all their templates.The reason I want this function is because my data is not static but I would like to use swig. By supporting this function from swig I can precompile my templates. Use them on the server or send them to the browser with dynamically loaded data.
Possible future additions could be turning options.precompile into an object with a glob. Only files matching the globs would be precompiled, the rest could be compiled to static HTML. This is however more than I need at the moment and probably more confusing than my current solution.
As per the swig documentation, any function resulting from
opts.precompile = true
oropts.precompile = "<%= template %>" should be used with
swig.run`.