Created
May 16, 2023 14:05
-
-
Save joshuafredrickson/3255bbad1c2ca4dbea1803aa5f19047e to your computer and use it in GitHub Desktop.
Dynamically loading Alpine components on page load.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import domReady from '@roots/sage/client/dom-ready'; | |
/** | |
* Alpine components | |
*/ | |
import Alpine from 'alpinejs'; | |
import * as components from './components/index.js'; | |
/** | |
* Application entrypoint | |
*/ | |
domReady(async () => { | |
// Kickstart our Alpine components | |
Object.keys(components).forEach((component) => { | |
let data = components[component](); | |
Alpine.data(component, () => data); | |
}); | |
Alpine.start(); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import dropdown from './dropdown.js'; | |
import modal from './modal.js'; | |
import nav from './nav.js'; | |
export {dropdown, modal, nav}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment