diff --git a/psb.cabal b/psb.cabal index 6382b6e..856035e 100644 --- a/psb.cabal +++ b/psb.cabal @@ -27,7 +27,7 @@ common warnings library hs-source-dirs: src - exposed-modules: Markdown HTML Logger IR Logger.Shake Psb.Main Utilities Utilities.FilePath Utilities.Action Utilities.Javascript Utilities.CSS Templates Types Config + exposed-modules: Markdown HTML Logger IR Logger.Shake Psb.Main Utilities Utilities.FilePath Utilities.Action Utilities.Javascript Utilities.CSS Templates Types Config Utilities.Bundling other-modules: Utilities.Parsing build-depends: base >=4.20 && < 4.21, mustache >=2.4.2, shake >= 0.19.8, deriving-aeson >= 0.2.9, aeson, text >= 2.1.2, time, unordered-containers, yaml, megaparsec >= 9.7.0, transformers >= 0.6.2, css-syntax >= 0.1.0.2 default-extensions: ApplicativeDo DataKinds NamedFieldPuns DerivingVia LambdaCase TypeApplications DeriveGeneric OverloadedRecordDot NamedFieldPuns DuplicateRecordFields DisambiguateRecordFields FlexibleInstances diff --git a/src/Psb/Main.hs b/src/Psb/Main.hs index c96c6c9..b21b504 100644 --- a/src/Psb/Main.hs +++ b/src/Psb/Main.hs @@ -26,6 +26,7 @@ import Text.Megaparsec (errorBundlePretty) import Text.Mustache (ToMustache (toMustache)) import Types import Utilities.Action (getPublishedPosts, isDraft', markdownToHtml, markdownToPost, now, psbProgress) +import Utilities.Bundling (bundled) import qualified Utilities.CSS as CSS import Utilities.FilePath (indexHtmlOutputPath, indexHtmlSourcePaths, isMarkdownPost, urlConvert) import qualified Utilities.Javascript as JS @@ -73,10 +74,12 @@ buildRules :: Rules () buildRules = do home assets + bundled postsRule rss - css_resources - js_resources + +-- css_resources +-- js_resources -- make a rule of the pattern outputDir/asset_name which copes from outputDir/../pages assets :: Rules () @@ -85,20 +88,20 @@ assets = let src = FP.dropDirectory1 target Shake.copyFileChanged src target -css_resources :: Rules () -css_resources = - map (outputDir ) cssGlobs |%> \target -> do - src <- Shake.readFile' $ FP.dropDirectory1 target - -- TODO: write to fingerprinted location as well - Shake.writeFileChanged target $ CSS.minify src - -js_resources :: Rules () -js_resources = - map (outputDir ) jsGlobs |%> \target -> do - let src_file = FP.dropDirectory1 target - src <- Shake.readFile' $ src_file - -- TODO: write to fingerprinted location as well - Shake.writeFileChanged target $ JS.minify src +-- css_resources :: Rules () +-- css_resources = +-- map (outputDir ) cssGlobs |%> \target -> do +-- src <- Shake.readFile' $ FP.dropDirectory1 target +-- -- TODO: write to fingerprinted location as well +-- Shake.writeFileChanged target $ CSS.minify src +-- +-- js_resources :: Rules () +-- js_resources = +-- map (outputDir ) jsGlobs |%> \target -> do +-- let src_file = FP.dropDirectory1 target +-- src <- Shake.readFile' $ src_file +-- -- TODO: write to fingerprinted location as well +-- Shake.writeFileChanged target $ JS.minify src -- there's probably a better way of doing this that allows for the target's origin file extension to get passed in but for now we're doing brute force postsRule :: Rules () diff --git a/src/Utilities/Bundling.hs b/src/Utilities/Bundling.hs new file mode 100644 index 0000000..c31afb2 --- /dev/null +++ b/src/Utilities/Bundling.hs @@ -0,0 +1,20 @@ +module Utilities.Bundling + ( bundled, + ) +where + +import Development.Shake (Action, Rules, command_) + +-- does not include specification of output location or input files +generic_esbuild_options :: [String] +generic_esbuild_options = ["--minify", "--sourcemap", "--bundle", "--chunk-names=[name]-[hash]"] + +-- TODO: not sure if I want all bundling to be an all at once afair, per file format +-- or multiple stages for various formats +-- +-- Regardless the objective is to produce all of that while outputting a file to +-- indicate completion/fulfill a need directive without rebuilding even when files +-- are left unchanged, maybe have the need be a $(filename).hash which we compute +-- ourselves based on the unminified input +bundled :: Rules () +bundled = error "TODO"