Skip to content

Instantly share code, notes, and snippets.

@lassemt
Created March 15, 2019 08:09
Show Gist options
  • Save lassemt/87869923e522d19b799094164469ec66 to your computer and use it in GitHub Desktop.
Save lassemt/87869923e522d19b799094164469ec66 to your computer and use it in GitHub Desktop.
Dynamic module import
//
// Async loading modules
//
const AsyncModules = async () => {
// Load and setup forms
let formEls = [...document.querySelectorAll('.Form--ajax')];
if (formEls.length) {
const Forms = await import(/* webpackChunkName: "forms" */ './components/Forms');
formEls.map(formEl => new Forms(formEl));
}
};
//
// Theme
//
const Theme = {
// DOM ready
init () {
// Dynamic import
AsyncModules().then( () => {
console.log('Modules loaded');
});
}
};
document.addEventListener('DOMContentLoaded', () => Theme.init());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment