diff --git a/frontend/package.json b/frontend/package.json index 742a0df..fcd75f4 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -31,6 +31,7 @@ "bower": "^1.7.9", "connect-history-api-fallback": "^1.2.0", "express": "^4.13.4", + "favicons-webpack-plugin": "0.0.7", "html-webpack-plugin": "^2.15.0", "http-server": "^0.9.0", "purescript": "^0.10.1", @@ -40,7 +41,8 @@ "react-document-title": "^2.0.2", "react-dom": "^15.0.0", "rimraf": "^2.5.2", - "webpack": "^2.1.0-beta.25" + "webpack": "^2.1.0-beta.25", + "webpack-uglify-js-plugin": "^1.1.9" }, "devDependencies": { "source-map-loader": "^0.1.5", diff --git a/frontend/src/BlogEntry.purs b/frontend/src/BlogEntry.purs index f64f127..9286619 100644 --- a/frontend/src/BlogEntry.purs +++ b/frontend/src/BlogEntry.purs @@ -9,9 +9,9 @@ import Data.Maybe (Maybe(..)) import Network.HTTP.Affjax (AJAX, get) import Prelude (bind, pure, show, ($), (<>), (<<<)) import Pux (EffModel, noEffects) -import Pux.Html (Html, div, h1, p, text) -import Pux.Html.Attributes (className, id_, title) import Pux.DocumentTitle (documentTitle) +import Pux.Html (Html, div, h1, p, text) +import Pux.Html.Attributes (dangerouslySetInnerHTML, className, id_, title) data Action = RequestPost | ReceivePost (Either String Post) @@ -76,5 +76,5 @@ view { id: id, status: status, post: (Post post) } = [ h1 [] [ text status ] , documentTitle [ title $ post.title <> " - Christine Dodrill" ] [] , div [ className "col s8 offset-s2" ] - [ p [ id_ "blogpost" ] [ text post.body ] ] + [ p [ id_ "blogpost", dangerouslySetInnerHTML post.body ] [] ] ] diff --git a/frontend/src/Main.purs b/frontend/src/Main.purs index 5f42a8a..09030f3 100644 --- a/frontend/src/Main.purs +++ b/frontend/src/Main.purs @@ -1,13 +1,13 @@ module Main where -import App.Routes (match) import App.Layout (Action(PageView), State, view, update) +import App.Routes (match) import Control.Bind ((=<<)) import Control.Monad.Eff (Eff) import DOM (DOM) import Network.HTTP.Affjax (AJAX) import Prelude (bind, pure) -import Pux (App, Config, CoreEffects, renderToDOM, start) +import Pux (renderToDOM, renderToString, App, Config, CoreEffects, start) import Pux.Devtool (Action, start) as Pux.Devtool import Pux.Router (sampleUrl) import Signal ((~>)) @@ -44,3 +44,10 @@ debug state = do renderToDOM "#app" app.html -- | Used by hot-reloading code in support/index.js pure app + +-- | Entry point for server side rendering +ssr :: State -> Eff (CoreEffects AppEffects) String +ssr state = do + app <- start =<< config state + res <- renderToString app.html + pure res diff --git a/frontend/support/index.js b/frontend/support/index.js index 3ab610e..9f6020d 100644 --- a/frontend/support/index.js +++ b/frontend/support/index.js @@ -11,3 +11,15 @@ if (module.hot) { } else { Main[debug ? 'debug' : 'main'](initialState)(); } + +global.main = function(args, callback) { + var body = Main['ssr'](initialState)(); + + result = { + "app": body, + "uuid": args.uuid, + "title": "Christine Dodrill" + } + + callback(result); +}; diff --git a/frontend/webpack.production.config.js b/frontend/webpack.production.config.js index 00486d7..ac58a43 100644 --- a/frontend/webpack.production.config.js +++ b/frontend/webpack.production.config.js @@ -1,6 +1,8 @@ var path = require('path'); var webpack = require('webpack'); var HtmlWebpackPlugin = require('html-webpack-plugin'); +var webpackUglifyJsPlugin = require('webpack-uglify-js-plugin'); +var FaviconsWebpackPlugin = require('favicons-webpack-plugin'); module.exports = { entry: [ path.join(__dirname, 'support/index.js') ], @@ -37,6 +39,20 @@ module.exports = { inject: 'body', filename: 'index.html' }), + new FaviconsWebpackPlugin('../static/img/avatar.png'), + new webpack.optimize.DedupePlugin(), + new webpackUglifyJsPlugin({ + cacheFolder: path.resolve(__dirname, 'output/ug'), + debug: false, + minimize: true, + sourceMap: false, + output: { + comments: false + }, + compressor: { + warnings: false + } + }), ], resolveLoader: { modules: [