Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(precompile): allow for precompilation #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

feature(precompile): allow for precompilation #27

wants to merge 1 commit into from

Conversation

Kingdutch
Copy link

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 or opts.precompile = "<%= template %>" should be used withswig.run`.

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 "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` or `opts.precompile = "<%= template %>" should be used with `swig.run`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant