-
-
Notifications
You must be signed in to change notification settings - Fork 493
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
Trigger builds programmatically via JavaScript API without the cli #620
Comments
Have you looked at cmd.js? |
I hadn't looked at it yet, but I think you're right that it could potentially have what I need. Thanks! If I'm able to trigger builds with some of that code, I'll post an update. |
I came here to request this feature so that I can use the step-through debugger.
This isn't a very ergonomic solution, as I want to be able to just |
Right. I haven't had success triggering builds from my app via JavaScript, using something like |
I did post a quick example of this here https://twitter.com/zachleat/status/1167115558552244226 but work is ongoing here for something official |
So I got this to run from /**
* Set up a listener to rebuild on changes made in Sanity.
* Add a token to .env.development to rebuild on all changes.
*/
async function preview() {
const client = require('./utils/sanityClient')
const Eleventy = require("@11ty/eleventy");
let inst = new Eleventy();
await inst.init();
await client.listen('*').subscribe(async doc => {
await inst.write();
})
}
setTimeout(() => preview(), 200) It now rebuilds when the listener register changes via the API. |
@kmelve Do you think that |
One of my colleagues suggested it is because we have modules/files that’s reference each other. So it has nothing to do with Sanity, or Eleventy, but this: https://nodejs.org/api/modules.html#modules_cycles. I think I’ll just bring the preview function into a separate file and run it concurrently from package.json. There’s no reason it has to be in the config file outside of having stuff in one place. |
If you do build a normal API, it would be really nice if 11ty could produce a stream that can be consumed by Gulp. As it stands, one must built to a temp directory first.... |
So @zachleat has this example here: https://gist.github.com/zachleat/5b5ae0ddadbeba6169f18e5b4aa58a66 Problem is, AFAICT, that the config still comes from a
https://github.com/11ty/eleventy/blob/master/src/Eleventy.js#L30 In a cloud function this could be a problem since you may need to determine paths dynamically at runtime. Is there a way to pass the config to the |
Note that #136 had an additional 37 votes at time of closing.
|
For anyone that may still be interested, I've found an answer to @PierBover's question
It seems the const Eleventy = require("@11ty/eleventy");
(async function() {
let inst = new Eleventy();
inst.config = { /*my custom config*/ };
await inst.init();
await inst.write();
})(); |
@PierBover and @blake-mealey, you can also use the (async function() {
const ssg = new Eleventy();
// Pass a JavaScript file which exports an object:
ssg.setConfigPathOverride('./config/vendor/eleventy.js');
await ssg.init();
await ssg.write();
})(); |
Note that 1.0 will have this functionality too. https://twitter.com/zachleat/status/1358966988203323394 Subscribe to #1629 |
Removing this from the enhancement queue, moving to the 1.0 milestone. |
First draft of the docs for this feature are available: https://www.11ty.dev/docs/programmatic/ |
Is it possible to trigger a build via JavaScript without using the cli (i.e.
npx eleventy
)?I've wrapped Eleventy in an Electron application, I would like to trigger new builds on button click, after updating data via form entry--but I'm not sure how to trigger builds via API without running the cli.
The text was updated successfully, but these errors were encountered: