public static FilesTransformer Defaults(Action <FilesTransformer>?with = null) { var options = new FilesTransformer { FileExtensions = { ["html"] = new FileTransformerOptions { BlockTransformers = { new RawBlock("<!--raw-->", "<!--/raw-->", Run.Always), new MinifyBlock("<!--minify-->", "<!--/minify-->", Minifiers.HtmlAdvanced,Run.IgnoreInDebug), new MinifyBlock("<script minify>", "</script>", Minifiers.JavaScript, Run.IgnoreInDebug) { LineTransformers = FilesTransformer.JsLineTransformers.ToList(), Convert = js => "<script>" + js + "</script>", }, new MinifyBlock("<style minify>", "</style>", Minifiers.Css, Run.IgnoreInDebug) { Convert = css => "<style>" + css + "</style>" }, new RemoveBlock("/**", "*/", Run.IgnoreInDebug), }, LineTransformers = FilesTransformer.HtmlLineTransformers.ToList(), }, ["js"] = new FileTransformerOptions { BlockTransformers = { new RawBlock("/*raw:*/", "/*:raw*/", Run.Always), new MinifyBlock("/*minify:*/", "/*:minify*/", Minifiers.JavaScript, Run.IgnoreInDebug) { LineTransformers = FilesTransformer.JsLineTransformers.ToList() }, new RemoveBlock("/**", "*/", Run.IgnoreInDebug), }, LineTransformers = FilesTransformer.JsLineTransformers.ToList(), }, ["css"] = new FileTransformerOptions { BlockTransformers = { new RawBlock("/*raw:*/", "/*:raw*/", Run.Always), new MinifyBlock("/*minify:*/", "/*:minify*/", Minifiers.Css, Run.IgnoreInDebug), new RemoveBlock("/**", "*/", Run.IgnoreInDebug), }, LineTransformers = FilesTransformer.CssLineTransformers.ToList(), }, }, }; with?.Invoke(options); return(options); }
public static FilesTransformer Minify(this FilesTransformer options, Minify minify, Run behavior = Run.OnlyInDebug) => options.Clone(with: o => { if (minify.HasFlag(Html.Minify.JavaScript)) { o.GetExt("js")?.FilesTransformers.Add(new MinifyBlock(Minifiers.JavaScript, behavior)); } if (minify.HasFlag(Html.Minify.Css)) { o.GetExt("css")?.FilesTransformers.Add(new MinifyBlock(Minifiers.Css, behavior)); } if (minify.HasFlag(Html.Minify.HtmlAdvanced)) { o.GetExt("html")?.FilesTransformers.Add(new MinifyBlock(Minifiers.HtmlAdvanced, behavior)); } if (minify.HasFlag(Html.Minify.Html)) { o.GetExt("html")?.FilesTransformers.Add(new MinifyBlock(Minifiers.Html, behavior)); } });