metalsmith / layouts

A metalsmith plugin for layouts
MIT License
116 stars 49 forks source link

Nunjucks: disabling cache doesn't work #108

Closed jvolker closed 8 years ago

jvolker commented 8 years ago

I'm trying to use metalsmith-layouts with metalsmith-watch and watch the source and template directories.

.use(
    watch({
      paths: {
        ["./source/**/*"] : true, // every changed files will trigger a rebuild of themselves 
        ["./template/**/*"] : "**/*" // every templates changed will trigger a rebuild of all files
      },
      livereload: true
    })
)

Whenever I change my main template file home.njk the browser refreshes satisfyingly.

However I'm also using Nunjucks' include tag to pull in template partials. Nunjucks by default caches files being included. Whenever I change one of these files the change is not visible in the browser, even after a refresh. When I run the whole build script again, the change is visible.

I tried passing cache: false in the metalsmith-layouts configuration. But it does not have any effect.

Thanks!

jvolker commented 8 years ago

As a workaround I'm now doing the following:

var nunjucks = require('nunjucks');

nunjucks.configure('./template', {
  watch: true,
  noCache : true
});
.use(layouts({
  engine: 'nunjucks',
  requires: {
    "nunjucks" : nunjucks
  },
  directory: './template/',
  _partials: 'partials/',
})

I can then use includes like this:

{% include _partials + "head.njk" %}
ismay commented 8 years ago

I tried passing cache: false in the metalsmith-layouts configuration. But it does not have any effect.

That could be. Whether passing cache: false does anything is determined by consolidate. It handles the caching, and might not clear the cache for nunjucks templates, see here. I'd suggest you to check there, as we're dependent on the way consolidate handles this.

Let me know if anything related to layouts pops up.