MaybeThisIsRu / smix-eleventy-starter

A standards-respecting starter kit for Eleventy. Go Indie.
https://smix.netlify.app/
MIT License
117 stars 8 forks source link

Automatic reloads on certain workflow tasks (such as CSS or JS compilation) #23

Closed MaybeThisIsRu closed 2 years ago

MaybeThisIsRu commented 3 years ago

From the README:

Todo:

  • Reload automatically after our assets change (filed issue here, waiting for response/PR approval). Please reload manually for now.

This PR has been approved and merged in by Zach. We can finally plug in to Eleventy's server and trigger a reload when our CSS or JS tasks finish (or any other). :)

Thibaultfq commented 3 years ago

Could you give any indication on how to call the reload function in the gulp.babel.js file? I gave this an attempt but it actually left me quite puzzling... Also, what should the reload function return?

MaybeThisIsRu commented 3 years ago

Although the PR has been approved and merged, it has not yet made it into an official Eleventy release. It's targeted for v1; see milestone details here, you'll find the #1126 PR as a part of this milestone.

So we still don't have any control over the BrowserSync instance until Eleventy v1 is released.

MaybeThisIsRu commented 2 years ago

This should have been doable with something like...

// Reload after asset tasks finish running etc.
function reload() {
    const server = browserSync.get("eleventy-server");
    if (server)
        server.reload();
}

And adding it to the task series:

function cssWatcher() {
    return watch(
        [`${paths.css.src}/**/*.css`, ...paths.css.additionalWatch],
        series(css, reload)
    );
}

That does not seem to work:

[23:10:05] Error: An instance with the name `eleventy-server` was not found.
    at Function.get (/Users/____/Code/smix-eleventy-starter/node_modules/browser-sync/lib/index.js:45:11)
    at reload (/Users/____/Code/smix-eleventy-starter/gulp_tasks/eleventy.babel.js:20:29)
    at bound (node:domain:421:15)
    at runBound (node:domain:432:12)
    at asyncRunner (/Users/____/Code/smix-eleventy-starter/node_modules/async-done/index.js:55:18)
    at processTicksAndRejections (node:internal/process/task_queues:78:11)
MaybeThisIsRu commented 2 years ago

^ And that's because I haven't yet locally updated to Eleventy 1.0. 🤦🏻‍♀️😬

MaybeThisIsRu commented 2 years ago

...and it still fails. Hmm.

MaybeThisIsRu commented 2 years ago

Might be because Eleventy is run as a child process?

MaybeThisIsRu commented 2 years ago

I probably don't have the bandwidth for this. The time and headache that will sink into this is not worth it. Manual reloads ftw. :(