uglify javascript

This commit is contained in:
Cadey Ratio 2016-12-17 21:14:25 -08:00
parent dee2a2605c
commit 62ffa5f008
5 changed files with 43 additions and 6 deletions

View File

@ -31,6 +31,7 @@
"bower": "^1.7.9", "bower": "^1.7.9",
"connect-history-api-fallback": "^1.2.0", "connect-history-api-fallback": "^1.2.0",
"express": "^4.13.4", "express": "^4.13.4",
"favicons-webpack-plugin": "0.0.7",
"html-webpack-plugin": "^2.15.0", "html-webpack-plugin": "^2.15.0",
"http-server": "^0.9.0", "http-server": "^0.9.0",
"purescript": "^0.10.1", "purescript": "^0.10.1",
@ -40,7 +41,8 @@
"react-document-title": "^2.0.2", "react-document-title": "^2.0.2",
"react-dom": "^15.0.0", "react-dom": "^15.0.0",
"rimraf": "^2.5.2", "rimraf": "^2.5.2",
"webpack": "^2.1.0-beta.25" "webpack": "^2.1.0-beta.25",
"webpack-uglify-js-plugin": "^1.1.9"
}, },
"devDependencies": { "devDependencies": {
"source-map-loader": "^0.1.5", "source-map-loader": "^0.1.5",

View File

@ -9,9 +9,9 @@ import Data.Maybe (Maybe(..))
import Network.HTTP.Affjax (AJAX, get) import Network.HTTP.Affjax (AJAX, get)
import Prelude (bind, pure, show, ($), (<>), (<<<)) import Prelude (bind, pure, show, ($), (<>), (<<<))
import Pux (EffModel, noEffects) 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.DocumentTitle (documentTitle)
import Pux.Html (Html, div, h1, p, text)
import Pux.Html.Attributes (dangerouslySetInnerHTML, className, id_, title)
data Action = RequestPost data Action = RequestPost
| ReceivePost (Either String Post) | ReceivePost (Either String Post)
@ -76,5 +76,5 @@ view { id: id, status: status, post: (Post post) } =
[ h1 [] [ text status ] [ h1 [] [ text status ]
, documentTitle [ title $ post.title <> " - Christine Dodrill" ] [] , documentTitle [ title $ post.title <> " - Christine Dodrill" ] []
, div [ className "col s8 offset-s2" ] , div [ className "col s8 offset-s2" ]
[ p [ id_ "blogpost" ] [ text post.body ] ] [ p [ id_ "blogpost", dangerouslySetInnerHTML post.body ] [] ]
] ]

View File

@ -1,13 +1,13 @@
module Main where module Main where
import App.Routes (match)
import App.Layout (Action(PageView), State, view, update) import App.Layout (Action(PageView), State, view, update)
import App.Routes (match)
import Control.Bind ((=<<)) import Control.Bind ((=<<))
import Control.Monad.Eff (Eff) import Control.Monad.Eff (Eff)
import DOM (DOM) import DOM (DOM)
import Network.HTTP.Affjax (AJAX) import Network.HTTP.Affjax (AJAX)
import Prelude (bind, pure) 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.Devtool (Action, start) as Pux.Devtool
import Pux.Router (sampleUrl) import Pux.Router (sampleUrl)
import Signal ((~>)) import Signal ((~>))
@ -44,3 +44,10 @@ debug state = do
renderToDOM "#app" app.html renderToDOM "#app" app.html
-- | Used by hot-reloading code in support/index.js -- | Used by hot-reloading code in support/index.js
pure app 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

View File

@ -11,3 +11,15 @@ if (module.hot) {
} else { } else {
Main[debug ? 'debug' : 'main'](initialState)(); 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);
};

View File

@ -1,6 +1,8 @@
var path = require('path'); var path = require('path');
var webpack = require('webpack'); var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin'); var HtmlWebpackPlugin = require('html-webpack-plugin');
var webpackUglifyJsPlugin = require('webpack-uglify-js-plugin');
var FaviconsWebpackPlugin = require('favicons-webpack-plugin');
module.exports = { module.exports = {
entry: [ path.join(__dirname, 'support/index.js') ], entry: [ path.join(__dirname, 'support/index.js') ],
@ -37,6 +39,20 @@ module.exports = {
inject: 'body', inject: 'body',
filename: 'index.html' 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: { resolveLoader: {
modules: [ modules: [