Skip to content

Programmatically invoke eleventy's .restart(), or watch variables #604

@khawkins98

Description

@khawkins98

I've successfully mapped a JS object (like this) and that's working smoothly.

What I'd now like to do is for the 11ty watch to trigger when that javascript changes.

Conceptual example:

myData.js

module.exports = {
  numberOfTweets: somePassedObjectOfTweets.tweetCount
};

Then when somePassedObjectOfTweets changes, I'd like for the 11ty watch to trigger; sort of something like this:

.eleventy.js

Object.observe(somePassedObjectOfTweets, function() {
  trigger11tyWatch();
});

Any ideas?

My workaround

For the time being I'm just doing this:

.eleventy.js

const touch = require("touch");
// https://www.npmjs.com/package/touch
Object.observe(somePassedObjectOfTweets, function() {
   touch('src/site/_data/myJsDataFile.js');
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions