refactor: avoid recompilation due to static files
This commit is contained in:
parent
b78c48465a
commit
7cf24a4187
@ -1574,20 +1574,9 @@ siteLayout' headingOverride widget = do
|
|||||||
frontendDatetimeLocale <- toJSON <$> selectLanguage frontendDatetimeLocales
|
frontendDatetimeLocale <- toJSON <$> selectLanguage frontendDatetimeLocales
|
||||||
|
|
||||||
pc <- widgetToPageContent $ do
|
pc <- widgetToPageContent $ do
|
||||||
$logDebugS "siteLayout" $ tshow webpackEntrypoint_main
|
webpackLinks_main StaticR
|
||||||
forM_ webpackEntrypoint_main $ \(sRoute, mime) ->
|
|
||||||
let ctEq = (==) `on` simpleContentType
|
|
||||||
in if
|
|
||||||
| mime `ctEq` "text/css"
|
|
||||||
-> addStylesheet $ StaticR sRoute
|
|
||||||
| mime `ctEq` "application/javascript"
|
|
||||||
-> addScript $ StaticR sRoute
|
|
||||||
| otherwise
|
|
||||||
-> $logErrorS "siteLayout" [st|Unknown mime type in webpack bundle: #{tshow mime}|]
|
|
||||||
|
|
||||||
toWidget $(juliusFile "templates/i18n.julius")
|
|
||||||
|
|
||||||
faviconLinks
|
faviconLinks
|
||||||
|
toWidget $(juliusFile "templates/i18n.julius")
|
||||||
|
|
||||||
$(widgetFile "default-layout")
|
$(widgetFile "default-layout")
|
||||||
withUrlRenderer $(hamletFile "templates/default-layout-wrapper.hamlet")
|
withUrlRenderer $(hamletFile "templates/default-layout-wrapper.hamlet")
|
||||||
|
|||||||
@ -12,7 +12,7 @@ import qualified Data.Yaml as Yaml
|
|||||||
|
|
||||||
import qualified Data.Map as Map
|
import qualified Data.Map as Map
|
||||||
|
|
||||||
import Yesod.Core (Route)
|
import Yesod.Core (Route, MonadLogger, MonadWidget, HandlerSite, logDebugS, logErrorS)
|
||||||
import Yesod.EmbeddedStatic (EmbeddedStatic)
|
import Yesod.EmbeddedStatic (EmbeddedStatic)
|
||||||
import Yesod.EmbeddedStatic.Types
|
import Yesod.EmbeddedStatic.Types
|
||||||
import Network.Mime (MimeType)
|
import Network.Mime (MimeType)
|
||||||
@ -27,6 +27,8 @@ import Utils (nubOn)
|
|||||||
|
|
||||||
import System.FilePath (makeRelative)
|
import System.FilePath (makeRelative)
|
||||||
|
|
||||||
|
import Text.Shakespeare.Text (st)
|
||||||
|
|
||||||
|
|
||||||
mkWebpackEntrypoints :: FilePath -- ^ Path to YAML-manifest
|
mkWebpackEntrypoints :: FilePath -- ^ Path to YAML-manifest
|
||||||
-> [FilePath -> Generator]
|
-> [FilePath -> Generator]
|
||||||
@ -54,11 +56,30 @@ mkWebpackEntrypoints manifest mkGen stDir = do
|
|||||||
Just n -> tell $ pure (n, ebMimeType entry)
|
Just n -> tell $ pure (n, ebMimeType entry)
|
||||||
|
|
||||||
let entryName = mkName $ "webpackEntrypoint_" <> entrypoint
|
let entryName = mkName $ "webpackEntrypoint_" <> entrypoint
|
||||||
|
widgetName = mkName $ "webpackLinks_" <> entrypoint
|
||||||
|
|
||||||
|
staticR <- newName "staticR"
|
||||||
sequence
|
sequence
|
||||||
[ sigD entryName [t|[(Route EmbeddedStatic, MimeType)]|]
|
[ sigD entryName [t|[(Route EmbeddedStatic, MimeType)]|]
|
||||||
, funD entryName
|
, funD entryName
|
||||||
[ clause [] (normalB . listE . map (\(n, mime) -> tupE [varE n, TH.lift mime]) $ nubOn fst entries) []
|
[ clause [] (normalB . listE . map (\(n, mime) -> tupE [varE n, TH.lift mime]) $ nubOn fst entries) []
|
||||||
]
|
]
|
||||||
|
, sigD widgetName [t|forall m. (MonadLogger m, MonadWidget m) => (Route EmbeddedStatic -> Route (HandlerSite m)) -> m ()|]
|
||||||
|
, funD widgetName
|
||||||
|
[ clause [varP staticR] (normalB [e|
|
||||||
|
do
|
||||||
|
$logDebugS "siteLayout" $ tshow $(varE entryName)
|
||||||
|
forM_ $(varE entryName) $ \(sRoute, mime) ->
|
||||||
|
let ctEq = (==) `on` simpleContentType
|
||||||
|
in if
|
||||||
|
| mime `ctEq` "text/css"
|
||||||
|
-> addStylesheet $ $(varE staticR) sRoute
|
||||||
|
| mime `ctEq` "application/javascript"
|
||||||
|
-> addScript $ $(varE staticR) sRoute
|
||||||
|
| otherwise
|
||||||
|
-> $logErrorS "siteLayout" [st|Unknown mime type in webpack bundle: #{tshow mime}|]
|
||||||
|
|]) []
|
||||||
|
]
|
||||||
]
|
]
|
||||||
where
|
where
|
||||||
decodeManifest :: FilePath -> Q (Map String [FilePath])
|
decodeManifest :: FilePath -> Q (Map String [FilePath])
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user