Skip to content

feat: add asyncDirective - #58

Open
Accudio wants to merge 3 commits into
mainfrom
feature/async-directive
Open

feat: add asyncDirective#58
Accudio wants to merge 3 commits into
mainfrom
feature/async-directive

Conversation

@Accudio

@Accudio Accudio commented Jun 5, 2026

Copy link
Copy Markdown
Owner

Adds a new function asyncDirective that allows for loading custom Alpine directives via a dynamic import. This will wait until Alpine executes a directive before downloading it.

This is very simple and just is a convenience wrapper for handling it yourself with dynamic imports, as Alpine.js supports async directives natively.

I'm not going to add conditional loading with a different API surface without significant demand for it due to amount of code for a relatively specific use-case.

Usage:

Alpine.asyncDirective('gsap', () => import('./src/gsap.js'))

I've just added the function version at the moment and it's the most practical, I'm happy to add URL and alias if it would be useful to people.

This work is primarily developed by @mickaelchanrion, from PR #56. Thank you very much to them for the work!

@Accudio

Accudio commented Jun 5, 2026

Copy link
Copy Markdown
Owner Author

Hi @mickaelchanrion, could you please give this a try and see if it meets your needs?

This is a rework of your PR #55 that relies more on Alpine's native async directive handling rather than extending parseName etc where it isn't required — with the goal of making it a bit simpler.

If this looks good I'll release this as version 2.1.0 asap.

@Accudio

Accudio commented Jun 5, 2026

Copy link
Copy Markdown
Owner Author

Test failure is due to module-crossorigin test which is not caused by this PR, and I'll look into separately. Happy to merge with that test failing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants