Skip to content

Instantly share code, notes, and snippets.

@zachleat
Created August 29, 2019 16:43
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zachleat/5b5ae0ddadbeba6169f18e5b4aa58a66 to your computer and use it in GitHub Desktop.
Save zachleat/5b5ae0ddadbeba6169f18e5b4aa58a66 to your computer and use it in GitHub Desktop.
Using Eleventy Programmatically
const Eleventy = require("@11ty/eleventy");
(async function() {
let inst = new Eleventy();
await inst.init();
await inst.write();
})();
@ki9us
Copy link

ki9us commented Dec 13, 2021

Is there documentation for this?

If I want to run another build, should I just re-run inst.write() or the whole function?

@ki9us
Copy link

ki9us commented Dec 14, 2021

I just ran this verbatim and inst.init() just hung.

@zachleat
Copy link
Author

I’m don’t remember the context of this gist but 11ty/eleventy#1629 (comment) might be a better bet. Couple of things:

  1. this isn’t an officially supported use case yet.
  2. That said, I think the only thing about the original that I would consider off is the instantiation. new Eleventy(input, output); are required

@ki9us
Copy link

ki9us commented Dec 15, 2021

Thanks. This does work:

const Eleventy = require("@11ty/eleventy");

(async function() {
	let inst = new Eleventy(".", "./_site");
	await inst.init();
	await inst.write();
})();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment