Skip to content

Nuglify

module Nuglify
AssemblyNacara.Plugin.Assets.Nuglify
Attributes[<RequireQualifiedAccess>]

Minifies what a site writes: its HTML, its JavaScript, its CSS.

One registration per format, so ask for the ones you want:

Site.create "My library"
|> Nuglify.minifyHtml
|> Nuglify.minifyJs
|> LightningCss.register   // the CSS, from a tool that also compiles it

Each touches its own format: minifying the HTML leaves style and script as it found them. Nothing is downloaded, and a file that cannot be parsed is written as it was and reported as a warning.

Functions and values

css (options: NuglifyCssOptions) (content: string) : Result<string,string>

Minify one stylesheet, or say why it could not be.

This minifies and stops there. LightningCss also compiles - nesting flattened, color-mix() computed, prefixes added for the browsers you name - so a site written in modern CSS wants that one instead. Register one or the other, never both.

Parameter
optionsWhat the site asked for.
contentThe stylesheet as it would have been written.
cssDefaults: NuglifyCssOptions
cssKeepLicenceComments (value: bool) (options: NuglifyCssOptions) : NuglifyCssOptions

Keep /*! … */ comments, where a licence lives.

Parameter
valueThe value to use.
optionsThe options so far.
cssMinifyWhileWatching (value: bool) (options: NuglifyCssOptions) : NuglifyCssOptions

Minify while watching too.

Parameter
valueThe value to use.
optionsThe options so far.
html (options: NuglifyHtmlOptions) (content: string) : Result<string,string>

Minify one document, or say why it could not be.

Parameter
optionsWhat the site asked for.
contentThe document as it would have been written.
htmlCollapseWhitespace (value: bool) (options: NuglifyHtmlOptions) : NuglifyHtmlOptions

Collapse runs of whitespace between elements.

Parameter
valueThe value to use.
optionsThe options so far.
htmlDefaults: NuglifyHtmlOptions
htmlKeepOneSpace (value: bool) (options: NuglifyHtmlOptions) : NuglifyHtmlOptions

Leave one space where a run of whitespace was, so nothing the reader sees moves.

Parameter
valueThe value to use.
optionsThe options so far.
htmlMinifyWhileWatching (value: bool) (options: NuglifyHtmlOptions) : NuglifyHtmlOptions

Minify while watching too.

Parameter
valueThe value to use.
optionsThe options so far.
htmlRemoveAttributeQuotes (value: bool) (options: NuglifyHtmlOptions) : NuglifyHtmlOptions

Remove quotes from attribute values that do not need them.

Parameter
valueThe value to use.
optionsThe options so far.
htmlRemoveComments (value: bool) (options: NuglifyHtmlOptions) : NuglifyHtmlOptions

Remove HTML comments.

Parameter
valueThe value to use.
optionsThe options so far.
htmlRemoveOptionalTags (value: bool) (options: NuglifyHtmlOptions) : NuglifyHtmlOptions

Remove end tags HTML5 says are optional - </body>, </li>.

Parameter
valueThe value to use.
optionsThe options so far.
js (options: NuglifyJsOptions) (content: string) : Result<string,string>

Minify one script, or say why it could not be.

Parameter
optionsWhat the site asked for.
contentThe script as it would have been written.
jsDefaults: NuglifyJsOptions
jsKeepLicenceComments (value: bool) (options: NuglifyJsOptions) : NuglifyJsOptions

Keep comments marked as important, the /*! … */ kind.

Parameter
valueThe value to use.
optionsThe options so far.
jsMinifyWhileWatching (value: bool) (options: NuglifyJsOptions) : NuglifyJsOptions

Minify while watching too.

Parameter
valueThe value to use.
optionsThe options so far.
jsShortenNames (value: bool) (options: NuglifyJsOptions) : NuglifyJsOptions

Shorten the names of local variables.

Parameter
valueThe value to use.
optionsThe options so far.
minifyCss (site: Site) : Site

Minify the site's CSS.

Use this or LightningCss.register, not both.

Parameter
siteThe site you are describing.
minifyCssWith (configure: NuglifyCssOptions -> NuglifyCssOptions) (site: Site) : Site

Minify the site's CSS, configured.

Parameter
configureGiven the defaults, the options to use.
siteThe site you are describing.
minifyHtml (site: Site) : Site

Minify the site's HTML.

Parameter
siteThe site you are describing.
minifyHtmlWith (configure: NuglifyHtmlOptions -> NuglifyHtmlOptions) (site: Site) : Site

Minify the site's HTML, configured.

Parameter
configureGiven the defaults, the options to use.
siteThe site you are describing.
minifyJs (site: Site) : Site

Minify the site's JavaScript.

Parameter
siteThe site you are describing.
minifyJsWith (configure: NuglifyJsOptions -> NuglifyJsOptions) (site: Site) : Site

Minify the site's JavaScript, configured.

Parameter
configureGiven the defaults, the options to use.
siteThe site you are describing.