Ejemplo n.º 1
0
    // http://danielwertheim.se/2012/11/16/customizing-the-minification-of-javascript-in-asp-net-mvc4-allowing-reserved-words/
    public static string MinifyJavaScript(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();

        // 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.MinifyJavaScript(System.IO.File.ReadAllText(file, System.Text.Encoding.UTF8), cs));
            content.Append(";");
        }
        ret            = content.ToString();
        content.Length = 0;
        content        = null;

        return(ret);
    }
Ejemplo n.º 2
0
        private void ExecuteCruncher(ITaskItem scriptItem)
        {
            string script = File.ReadAllText(scriptItem.ItemSpec);

            ScriptCruncher         cruncher         = new ScriptCruncher();
            ScriptCruncherSettings cruncherSettings = new ScriptCruncherSettings()
            {
                StripDebugStatements         = false,
                OutputMode                   = Microsoft.Ajax.Utilities.OutputMode.SingleLine,
                IgnorePreprocessorDefines    = true,
                IgnoreConditionalCompilation = true,
                TermSemicolons               = true,
            };

            cruncherSettings.AddNoAutoRename("$");
            cruncherSettings.SetDebugNamespaces(null);

            string crunchedScript = cruncher.MinifyJavaScript(script, cruncherSettings);

            File.WriteAllText(scriptItem.ItemSpec, crunchedScript);
        }
Ejemplo n.º 3
0
 public ScriptBundle(string virtualPath)
     : base(virtualPath)
 {
     settings = new Microsoft.Ajax.Utilities.CodeSettings()
     {
         PreserveImportantComments = false
         //everything else default;
     };
 }
Ejemplo n.º 4
0
        private void ExecuteCruncher(ITaskItem scriptItem)
        {
            string script = File.ReadAllText(scriptItem.ItemSpec);

            ScriptCruncher cruncher = new ScriptCruncher();
            ScriptCruncherSettings cruncherSettings = new ScriptCruncherSettings() {
                StripDebugStatements = false,
                OutputMode = Microsoft.Ajax.Utilities.OutputMode.SingleLine,
                IgnorePreprocessorDefines = true,
                IgnoreConditionalCompilation = true
            };
            cruncherSettings.AddNoAutoRename("$");
            cruncherSettings.SetDebugNamespaces(null);

            string crunchedScript = cruncher.MinifyJavaScript(script, cruncherSettings);

            File.WriteAllText(scriptItem.ItemSpec, crunchedScript);
        }