11ty / eleventy

A simpler site generator. Transforms a directory of templates (of varying types) into HTML.
https://www.11ty.dev/
MIT License
16.91k stars 491 forks source link

Create a named instance of the browser-sync server #1125

Closed MaybeThisIsRu closed 3 years ago

MaybeThisIsRu commented 4 years ago

Is your feature request related to a problem? Please describe. I have a starter-kit geared towards eleventy. I was using my own browserSync server to get full control over when to trigger a reload (for example, after my css or img tasks finish). I recently switched to the internal browserSync server for various reasons - chief among them getting ready in anticipation of incremental builds.

eleventy is internally using browserSync as well and allows specifying options. However, the instance created is not a named instance. It is therefore not possible for my tasks to look up if there is any active server and then hook into it.

Describe the solution you'd like This should be a one line change here by passing a name string to the create() method.

https://github.com/11ty/eleventy/blob/master/src/EleventyServe.js#L119

This will then allow one to get the instance of the server and trigger page reloads when necessary.

I'll open a PR shortly.

Describe alternatives you've considered I have looked through the browserSync options as suggested in the docs. It is not possible to configure a name of the server through options.

Additional context I use gulp to create an asset pipeline and require the server to reload when my tasks finish. These tasks don't affect eleventy's built files.

Ryuno-Ki commented 4 years ago

Do you have suggestions for the name? Are there limitations or considerations to take into account?

MaybeThisIsRu commented 4 years ago

Do you have suggestions for the name?

The name can be anything, really - I've gone for eleventyServer in my PR.

Are there limitations or considerations to take into account?

Not that I'm aware of, sorry.

MaybeThisIsRu commented 4 years ago

This seems redundant as a replacement server is being explored in #1305.

MaybeThisIsRu commented 4 years ago

Sorry - reopened as it seems to be in preliminary stages. If and when a replacement is chosen, we can close this.

Either way, it's probably good to have linked to the issue so it is easily accessible in the context of the replacement.

zachleat commented 3 years ago

Agree! This is a great addition—thank you! The named instance is eleventy-server

zachleat commented 3 years ago

Fixed by #1126