From a573444d4026a8e83100fae1693de2ce580c1ab2 Mon Sep 17 00:00:00 2001 From: obedm503 Date: Sat, 24 Mar 2018 16:43:24 -0600 Subject: [PATCH] pass loader to bootstrap --- src/bootstrap.ts | 38 -------------------------------------- src/bootstrapper.ts | 30 ++++++++++++++++++++++++++++++ src/main.ts | 6 +++--- 3 files changed, 33 insertions(+), 41 deletions(-) delete mode 100644 src/bootstrap.ts create mode 100644 src/bootstrapper.ts diff --git a/src/bootstrap.ts b/src/bootstrap.ts deleted file mode 100644 index 7d6cea1..0000000 --- a/src/bootstrap.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { Aurelia, PLATFORM } from 'aurelia-framework'; - -const global = PLATFORM.global; - -function ready() { - if (!global.document || global.document.readyState === 'complete') { - return Promise.resolve(); - } - - return new Promise(resolve => { - function completed() { - global.document.removeEventListener('DOMContentLoaded', completed); - global.removeEventListener('load', completed); - resolve(); - } - global.document.addEventListener('DOMContentLoaded', completed); - global.addEventListener('load', completed); - }); -} - -async function preparePlatform(loader) { - const { initialize } = await import('aurelia-pal-browser'); - await initialize(); - await Promise.all([ - import('aurelia-dependency-injection'), - import('aurelia-router'), - import('aurelia-logging-console'), - ]); - return new Aurelia(loader); -} - -export async function bootstrap(host: Element) { - await ready(); - const loader = await new PLATFORM.Loader(); - const aurelia = await preparePlatform(loader); - aurelia.host = host; - return aurelia; -} diff --git a/src/bootstrapper.ts b/src/bootstrapper.ts new file mode 100644 index 0000000..feb0e18 --- /dev/null +++ b/src/bootstrapper.ts @@ -0,0 +1,30 @@ +import { PLATFORM } from 'aurelia-pal'; +import { initialize } from 'aurelia-pal-browser'; +import { Loader } from 'aurelia-loader'; +import { Aurelia } from 'aurelia-framework'; + +const global: Window = PLATFORM.global; + +function ready() { + if (!global.document || global.document.readyState === 'complete') { + return Promise.resolve(); + } + + return new Promise(resolve => { + function done() { + global.document.removeEventListener('DOMContentLoaded', done); + global.removeEventListener('load', done); + resolve(); + } + global.document.addEventListener('DOMContentLoaded', done); + global.addEventListener('load', done); + }); +} + +export async function bootstrap(host: Element, loader: Loader) { + await ready(); + await initialize(); + const aurelia = new Aurelia(loader); + aurelia.host = host; + return aurelia; +} diff --git a/src/main.ts b/src/main.ts index 93dc045..94c330c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,13 +1,13 @@ import 'reflect-metadata'; -import 'aurelia-loader-webpack'; +import { WebpackLoader } from 'aurelia-loader-webpack'; import { Aurelia, PLATFORM } from 'aurelia-framework'; -import { bootstrap } from './bootstrap'; +import { bootstrap } from './bootstrapper'; import { App } from 'app/app'; async function start() { const host = document.getElementById('root'); - const aurelia: Aurelia = await bootstrap(host); + const aurelia: Aurelia = await bootstrap(host, new WebpackLoader()); aurelia.use // add plugins here