slinkity / slinkity

To eleventy and beyond! The all-in-one tool for templates where you want them, component frameworks where you need them 🚀

Home Page:https://slinkity.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is vite ran on eleventy.after ?

aaronstezycki opened this issue · comments

Just wondering when Vite fires in the eleventy build process.

I've used a package with eleventy which also uses eleventy.after, and vite gets confused and doesn't render the effects of the package.

Ah, fair question! This is hooked in the eleventy.after build step yes. There's sadly no way to prioritize or deprioritize events in the 11ty lifecycle (i.e. Slinkity needs to go after after), so the best I can suggest is:

  1. Apply Slinkity at the top of your config
  2. Apply your eleventy.after calls inside a fake plugin applied after the Slinkity plugin

Here's an example:

// Apply slinkity first
eleventy.addPlugin(slinkity, {...})
// Apply your own plugin after, so it comes later in 11ty's queue
eleventy.addPlugin(function myAfterBuildStep(pluginConfig) {
  // wire your lifecycle events inside here
  pluginConfig.on('eleventy.after', async () => {...})
  })

Let me know if that helps!

Yeah, I'm not sure that helped as the plugin is currently added after defining the slinkity plugin. What the plugin does is add processing (syntax highlighting) to code blocks after 11ty has built... so an example output looks a little like ...

highlight 'index.html'
highlight 'about.html'
[vite] page reload ... etc.
highlight 'shop.html'
highlight 'contact.html'

So the process are running async, whereas in this case vite needs to wait for the plugin to finish before processing the html and then page reload.

Thanks for your help though.

@aaronstezycki Ah sorry, totally read your question backwards! but huh, I'd expect if you flip my solution (move myAfterBuildStep before applying the slinkity plugin), you can complete your processing before Vite steps in. I see you mention [vite] page reload though, so it sounds like this is a dev server issue and not a production build issue?

Yeah sorry for not pointing that out from the outset, so far i've only noticed the issue during the dev server cycle when using vite to run 11ty locally. Atm I've rolled back the plugin changes, but I will try out your suggestion. Thanks for further help :)

@aaronstezycki Thanks for the reply! I'll close this issue in the next day or so if there's no follow-ups 👍