Created
March 15, 2019 08:09
-
-
Save lassemt/87869923e522d19b799094164469ec66 to your computer and use it in GitHub Desktop.
Dynamic module import
This file contains 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
// | |
// 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