diff --git a/CHANGELOG.md b/CHANGELOG.md index ecec66e..f0d526c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Major refactor to bring dependencies up-to-date: - Upgrade Babel 5 -> 6 - Replace Karma and Istanbul with ava and nyc - No more custom routers +- Added server-side Babel require hook # v0.3.0 diff --git a/package.json b/package.json index e4bc2d6..0bbc0ac 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "src/main.js", "scripts": { "postinstall": "npm run build", - "server": "node server.js", + "server": "node start.js", "build": "webpack -p --progress --config webpack.production.config.js", "test": "nyc ava --fail-fast --verbose --require babel-register", "coveralls": "nyc report --reporter=text-lcov | coveralls", diff --git a/server.js b/server.js index 4c7d3b6..9627925 100644 --- a/server.js +++ b/server.js @@ -1,4 +1,4 @@ -const express = require('express'); +import express from 'express'; const app = express(); @@ -12,7 +12,7 @@ const app = express(); ************************************************************/ // Serve application file depending on environment -app.get('/app.js', function(req, res) { +app.get('/app.js', (req, res) => { if (process.env.PRODUCTION) { res.sendFile(__dirname + '/build/app.js'); } else { @@ -21,7 +21,7 @@ app.get('/app.js', function(req, res) { }); // Serve aggregate stylesheet depending on environment -app.get('/style.css', function(req, res) { +app.get('/style.css', (req, res) => { if (process.env.PRODUCTION) { res.sendFile(__dirname + '/build/style.css'); } else { @@ -30,7 +30,7 @@ app.get('/style.css', function(req, res) { }); // Serve index page -app.get('*', function(req, res) { +app.get('*', (req, res) => { res.sendFile(__dirname + '/build/index.html'); }); @@ -53,7 +53,7 @@ if (!process.env.PRODUCTION) { hot: true, noInfo: true, historyApiFallback: true - }).listen(9090, 'localhost', function (err, result) { + }).listen(9090, 'localhost', (err, result) => { if (err) { console.log(err); } @@ -68,7 +68,7 @@ if (!process.env.PRODUCTION) { *****************/ const port = process.env.PORT || 8080; -const server = app.listen(port, function () { +const server = app.listen(port, () => { const host = server.address().address; const port = server.address().port; diff --git a/start.js b/start.js new file mode 100644 index 0000000..166e2e8 --- /dev/null +++ b/start.js @@ -0,0 +1,5 @@ +// Server-side entrypoint that registers Babel's require() hook +const babelRegister = require('babel-register'); +babelRegister(); + +require('./server');