public static void p5_web_css_minify(ApplicationContext context, ActiveEventArgs e) { // House cleaning. using (new ArgsRemover(e.Args, true)) { // Iterating through each CSS content supplied, and minifying it, returning the results to caller. foreach (var idxCss in XUtil.Iterate <string> (context, e.Args)) { // Minifying CSS content. var minifier = new Microsoft.Ajax.Utilities.Minifier(); var options = new Microsoft.Ajax.Utilities.CssSettings(); options.CommentMode = Microsoft.Ajax.Utilities.CssComment.None; // Returning minified content to caller. e.Args.Add("result", minifier.MinifyStyleSheet(idxCss, options)); } } }
// msiexec /a D:\Temp\AjaxMinSetup.msi /qb TARGETDIR=D:\Temp\AjaxMinSetup\ // http://nickberardi.com/yahoo-yui-compressor-vs-microsoft-ajax-minifier-vs-google-closure-compiler/ // https://visualstudiogallery.msdn.microsoft.com/b1fff87e-d68b-4266-8bba-46fad76bbf22 // http://www.microsoft.com/en-us/download/details.aspx?id=48593 public static string MinifyCss(string[] filez) { string ret = null; System.Text.StringBuilder content = new System.Text.StringBuilder(); Microsoft.Ajax.Utilities.Minifier mifi = new Microsoft.Ajax.Utilities.Minifier(); Microsoft.Ajax.Utilities.CodeSettings cs = new Microsoft.Ajax.Utilities.CodeSettings(); Microsoft.Ajax.Utilities.CssSettings css = new Microsoft.Ajax.Utilities.CssSettings(); css.ColorNames = Microsoft.Ajax.Utilities.CssColor.Hex; css.CommentMode = Microsoft.Ajax.Utilities.CssComment.None; css.BlocksStartOnSameLine = Microsoft.Ajax.Utilities.BlockStart.SameLine; css.CssType = Microsoft.Ajax.Utilities.CssType.FullStyleSheet; css.IndentSize = 0; css.MinifyExpressions = true; // css.LineTerminator ="\n"; css.OutputMode = Microsoft.Ajax.Utilities.OutputMode.SingleLine; css.TermSemicolons = false; // cs.AddRenamePair("delete", "fooDelete"); cs.MinifyCode = true; cs.OutputMode = Microsoft.Ajax.Utilities.OutputMode.SingleLine; cs.CollapseToLiteral = true; cs.EvalTreatment = Microsoft.Ajax.Utilities.EvalTreatment.MakeAllSafe; cs.IndentSize = 0; cs.InlineSafeStrings = true; cs.LocalRenaming = Microsoft.Ajax.Utilities.LocalRenaming.CrunchAll; cs.MacSafariQuirks = true; cs.PreserveFunctionNames = true; cs.RemoveFunctionExpressionNames = true; cs.RemoveUnneededCode = true; cs.StripDebugStatements = true; cs.PreserveImportantComments = false; foreach (string file in filez) { content.Append(mifi.MinifyStyleSheet(System.IO.File.ReadAllText(file, System.Text.Encoding.UTF8), css, cs)); content.Append(";"); } ret = content.ToString(); content.Length = 0; content = null; return(ret); }
public StyleBundle(string virtualPath) : base(virtualPath) { settings = new Microsoft.Ajax.Utilities.CssSettings() { CommentMode = Microsoft.Ajax.Utilities.CssComment.None //everything else default; }; }