Add a custom nunjucks transformer, with caching#5150
Open
domoscargin wants to merge 4 commits intomainfrom
Open
Add a custom nunjucks transformer, with caching#5150domoscargin wants to merge 4 commits intomainfrom
domoscargin wants to merge 4 commits intomainfrom
Conversation
✅ You can preview this change here:
To edit notification comments on pull requests, go to your Netlify project configuration. |
2ecd33b to
f6b7a3c
Compare
f6b7a3c to
bed3a05
Compare
Adds a simple cache check against the nunjucks environment used in the transformer. Currently, each file that gets passed to the transformer by @metalsmith/in-place and @metalsmith-layouts sets up a new Nunjucks environment, which costs a lot of time. We only use one Nunjucks environment during build, though, so we don't need to keep setting a new one up. This dramatically cuts down in-place and layouts' build times.
bed3a05 to
b69e5a8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
@metalsmith/in-place and @metalsmith/layouts both use a Nunjucks jstransformer under the hood to render templates.
This transformer sets up a new Nunjucks environment per file, causing in-place and layouts to take a long time to run.
npm run buildwithout transformer cacheThis PR adds Nunjucks environment caching to the transformer, dramatically reducing build times for both plugins
npm run buildwith transformer cacheCached templates
The templates in
/viewsare cached by the Nunjucks environment. This means if we change one of these files, that change will not propagate to all the templates where it's used.To account for this, we watch the views directory and reset the Nunjucks environment cache whenever we detect a change to a file there.
We previously set the Nunjucks option
noCachetofalse. If we set that back totrue, it obliterates any gains from this PR's caching, so having this extra check/reset is preferable.