Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Run eleventy once before starting the server, then watch for changes. #5157

Merged
merged 1 commit into from
Apr 27, 2021

Conversation

robdodson
Copy link
Contributor

Fixes #3605, unblocks #5008

eleventy --watch will run eleventy, which means if you have an npm script (like our dev script) where you want to 1st run eleventy, and then watch for changes, you can't really do it without running eleventy twice (issue).

The solution is to write our own chokidar file watcher (which is what eleventy is using under the hood) to watch the src/site directory and re-run eleventy ourselves. Importantly, chokidar does not run your command when you first call the npm script.

Changes proposed in this pull request:

  • Replace eleventy --watch with our own chokidar watcher.

@google-cla google-cla bot added the cla: yes Contributor has signed the CLA label Apr 22, 2021
@pullapprove pullapprove bot requested review from MichaelSolati and samthor April 22, 2021 23:53
@netlify
Copy link

netlify bot commented Apr 22, 2021

Deploy preview for web-dev-staging ready!

Built with commit f901bff

https://deploy-preview-5157--web-dev-staging.netlify.app

@samthor
Copy link
Contributor

samthor commented Apr 23, 2021

My concerns were discussed in chat but I'll list them here:

re, Eleventy:

  • Eleventy is already slow in that it is O(n) to the number of pages we have. This is part of its premise; it's imperative so it needs to rebuild the entire site every time. I sent them a PR to only render the page you care about (since rendering should have no side effects and Nunjucks is very slow) but that's not been merged either.
  • It does however load a bunch of JS (its config) which is not reloaded on every rebuild, so there's some efficiencies there
  • We preclude ourselves from any future optimizations by going down this route.

re, making every user interact with prod things:

  • Average post author doesn't care about CSP or SWs or often even our JS build.
  • But Eleventy is so slow for our huge site anyway that probably those things are really minor compared to the ever-increasing O(n) of all our pages.
  • Perhaps we solve this by making editing part of CMS that lets you write your post in isolation, which is 90% of what people do when they interact with our repo(s), and then our repo is just for site engineers, not authors.

As @robdodson has pointed out, we can also roll this back of it's bad. But I wanted to get my thoughts on paper.

@robdodson
Copy link
Contributor Author

robdodson commented Apr 23, 2021

We preclude ourselves from any future optimizations by going down this route.

It doesn't seem like Eleventy has any immediate plans to do incremental builds (they've talked about it for years but I've not seen any recent progress). If they did ship incremental builds then we would replace this.

Average post author doesn't care about CSP or SWs or often even our JS build.

That's true, but the eng team also tends to not do prod builds before we merge stuff and deploy it. So we might shoot ourselves in the foot with a CSP change in dev, not realize it, and deploy. This kind of thing already happens because we don't run purgeCss in dev so we occasionally deploy broken UI. So it seems like it may actually be a good safe guard to do these in dev.

Perhaps we solve this by making editing part of CMS that lets you write your post in isolation, which is 90% of what people do when they interact with our repo(s), and then our repo is just for site engineers, not authors.

I'm really supportive of this and I think it's the direction eleventy is heading in. See this demo from Zach's talk at Sanity conf where he shows the Eleventy 1.0 progammatic API which lets you invoke eleventy and pass explicit content.

@robdodson
Copy link
Contributor Author

Also a somewhat minor point. The current build script is a bit broken because we start the server while eleventy is still running. So I occasionally here from authors "I tried to run the site and was getting 404s...oh wait, now it works!" This would fix that issue at least.

@robdodson robdodson force-pushed the feat/run-eleventy-then-watch branch from 07fedeb to f901bff Compare April 27, 2021 18:34
@robdodson robdodson merged commit f80da0e into main Apr 27, 2021
@robdodson robdodson deleted the feat/run-eleventy-then-watch branch April 27, 2021 18:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes Contributor has signed the CLA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clean up CLI output so authors know when to refresh the page.
2 participants