hjsmin JavaScript minifier for Hakyll

Posted on 30 October 2014

I discovered that by default Hakyll only can compressCssCompiler and there is no compressJsCompiler

So I’ve found hjsmin for this task


import Control.Applicative ((<$>))

import qualified Data.ByteString.Lazy.Char8 as LB
import qualified Data.Text as T
import qualified Data.Text.Encoding as E

import Text.Jasmine


match "js/*" $ do
    route idRoute
    compile compressJsCompiler


compressJsCompiler :: Compiler (Item String)
compressJsCompiler = fmap jasmin <$> getResourceString

jasmin :: String -> String
jasmin src = LB.unpack $ minify $ LB.fromChunks [(E.encodeUtf8 $ T.pack src)] 

It works pretty fine so I even think this should be somewhere in hakyll docs