Created
February 6, 2017 13:36
-
-
Save marsch/40f9dfc90da4a7b6711cf690dfdb7365 to your computer and use it in GitHub Desktop.
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
import di from './di' | |
import { ext } from 'xtpoint' | |
window.ext = ext | |
const modulesContext = require.context('../plugins', true, /^\.\/[^\/]+?\/bundle\.js$/) | |
if (module.hot) { | |
console.log('accept hot?!??!?!?') | |
module.hot.accept(modulesContext.id, () => { | |
console.log('context', modulesContext.id, 'hot reloaded') | |
const moduleInstance = __webpack_require__(moduleId) | |
if (moduleInstance && moduleInstance.bootstrap && typeof moduleInstance.bootstrap == 'function') { | |
moduleInstance.bootstrap(ext, di) | |
} | |
}) | |
} | |
const boot = (moduleId) => { | |
const moduleInstance = __webpack_require__(moduleId) // eslint-disable-line | |
if (moduleInstance && moduleInstance.bootstrap && typeof moduleInstance.bootstrap == 'function') { | |
moduleInstance.bootstrap(ext, di) | |
} | |
} | |
modulesContext.keys().forEach((file) => { | |
const moduleId = modulesContext.resolve(file) | |
boot(moduleId) | |
if (module.hot) { | |
module.hot.accept(moduleId, () => { | |
boot(moduleId) | |
ext.point('core.run').invoke('exec') | |
//run() | |
console.log('hot reloading.....', moduleId) | |
}) | |
} | |
}) | |
export const run = () => { | |
// help all plugins to configure themselves | |
// NOTE: async startup | |
const bundles = ext.point('core.define').invoke('exec', di) | |
Promise.all(bundles.value()).then(() => { | |
// actually execute the typical calls to attach the application to the dom (aka. initial render call) | |
ext.point('core.run').invoke('exec') | |
}) | |
} | |
export default run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment