Last active
January 11, 2017 00:55
-
-
Save niieani/c1ca0388e54fa46fe6129de9dec9501f to your computer and use it in GitHub Desktop.
Server Rendering Aurelia
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 * as path from 'path'; | |
import 'aurelia-polyfills'; | |
import {Options, NodeJsLoader} from 'aurelia-loader-nodejs'; | |
import {PLATFORM, DOM} from 'aurelia-pal'; | |
import {globalize} from 'aurelia-pal-nodejs'; | |
import {Aurelia} from 'aurelia-framework'; | |
// ignore importing '.css' files, useful only for Webpack codebases that do stuff like require('./file.css'): | |
require.extensions['.css'] = function (m, filename) { | |
return; | |
} | |
// set the root directory where the aurelia loader will resolve to | |
// this is the 'src' dir in case of skeleton | |
Options.relativeToDir = path.resolve(__dirname, 'src'); | |
process.on('unhandledRejection', function(reason, p) { | |
console.log('Possibly unhandled Rejection at: Promise ', p, ' reason: ', reason); | |
}); | |
// initialize PAL and set globals (window, document, etc.) | |
globalize(); | |
// needed by bootstrap: | |
global.$ = global.jQuery = require('jquery'); | |
// set the path you want to load: | |
document.location.hash = '/users'; | |
const aurelia = new Aurelia(new NodeJsLoader()); | |
aurelia.host = document.body; | |
aurelia.configModuleId = 'main'; | |
// note: this assumes your configure method awaits or returns the value of aurelia.setRoot(...) | |
// skeletons currently don't do that so you need to adjust | |
require('./src/main').configure(aurelia).then(() => { | |
// rendered HTML: | |
console.log(document.body.outerHTML); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment