当前位置: 首页>>代码示例>>C#>>正文


C# Minifier.MinifyJavaScript方法代码示例

本文整理汇总了C#中Microsoft.Ajax.Utilities.Minifier.MinifyJavaScript方法的典型用法代码示例。如果您正苦于以下问题:C# Minifier.MinifyJavaScript方法的具体用法?C# Minifier.MinifyJavaScript怎么用?C# Minifier.MinifyJavaScript使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Ajax.Utilities.Minifier的用法示例。


在下文中一共展示了Minifier.MinifyJavaScript方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CompressContent

 public string CompressContent(string content)
 {
     var minifer = new Minifier();
     if (codeSettings != null)
     {
         return minifer.MinifyJavaScript(content, codeSettings, globalNames);
     }
     else
     {
         return minifer.MinifyJavaScript(content, globalNames);
     }
 }
开发者ID:hbulhoes,项目名称:SquishIt,代码行数:12,代码来源:MsMinifier.cs

示例2: MinifyJavaScript

        private static MinificationResult MinifyJavaScript(Config config, string file)
        {
            string content = File.ReadAllText(file);
            var settings = JavaScriptOptions.GetSettings(config);

            if (config.Minify.ContainsKey("enabled") && config.Minify["enabled"].ToString().Equals("false", StringComparison.OrdinalIgnoreCase))
                return null;

            var minifier = new Minifier();

            string ext = Path.GetExtension(file);
            string minFile = file.Substring(0, file.LastIndexOf(ext)) + ".min" + ext;
            string mapFile = minFile + ".map";

            string result = minifier.MinifyJavaScript(content, settings);

            bool containsChanges = FileHelpers.HasFileContentChanged(minFile, result);

            if (!string.IsNullOrEmpty(result))
            {
                OnBeforeWritingMinFile(file, minFile, containsChanges);

                if (containsChanges)
                {
                    File.WriteAllText(minFile, result, new UTF8Encoding(true));
                }

                OnAfterWritingMinFile(file, minFile, containsChanges);

                GzipFile(config, minFile, containsChanges);
            }

            return new MinificationResult(result, null);
        }
开发者ID:PaulVrugt,项目名称:WebCompiler,代码行数:34,代码来源:FileMinifier.cs

示例3: MinifyFile

        private static void MinifyFile(string file, string minFile, CodeSettings settings, bool isBundle)
        {
            Minifier minifier = new Minifier();

            if (!isBundle)
            {
                minifier.FileName = Path.GetFileName(file);
            }

            string content = minifier.MinifyJavaScript(File.ReadAllText(file), settings);

            if (File.Exists(minFile) && content == File.ReadAllText(minFile))
                return;

            if (WESettings.GetBoolean(WESettings.Keys.GenerateJavaScriptSourceMaps))
            {
                content += "\r\n/*\r\n//# sourceMappingURL=" + Path.GetFileName(minFile) + ".map\r\n*/";
            }

            ProjectHelpers.CheckOutFileFromSourceControl(minFile);
            using (StreamWriter writer = new StreamWriter(minFile, false, new UTF8Encoding(true)))
            {
                writer.Write(content);
            }

            if (WESettings.GetBoolean(WESettings.Keys.JavaScriptEnableGzipping))
                CssSaveListener.GzipFile(file, minFile, content);
        }
开发者ID:kevinderudder,项目名称:WebEssentials2013,代码行数:28,代码来源:JavaScriptSaveListener.cs

示例4: Execute

        public override IEnumerable<PvcCore.PvcStream> Execute(IEnumerable<PvcCore.PvcStream> inputStreams)
        {
            var minifyStreams = inputStreams.Where(x => Regex.IsMatch(x.StreamName, @"\.(js|css)$"));
            var resultStreams = new List<PvcStream>();

            foreach (var inputStream in minifyStreams)
            {
                var fileContent = new StreamReader(inputStream).ReadToEnd();
                var minifier = new Minifier();
                var resultContent = inputStream.StreamName.EndsWith(".js") ? minifier.MinifyJavaScript(fileContent) : minifier.MinifyStyleSheet(fileContent);

                foreach (var error in minifier.ErrorList)
                {
                    Console.Error.WriteLine(error.ToString());
                }

                var dirName = Path.GetDirectoryName(inputStream.StreamName);
                var fileName = Path.GetFileNameWithoutExtension(inputStream.StreamName) + ".min" + Path.GetExtension(inputStream.StreamName);

                var resultStream = PvcUtil.StringToStream(resultContent, Path.Combine(dirName, fileName));
                resultStreams.Add(resultStream);
            }

            return inputStreams.Where(x => !minifyStreams.Any(y => y.StreamName == x.StreamName)).Concat(resultStreams);
        }
开发者ID:pvcbuild,项目名称:pvc-ajaxmin,代码行数:25,代码来源:PvcAjaxmin.cs

示例5: Compile

        public string Compile(IEnumerable<string> files)
        {
            var blocks = new List<Block>();
            // ReSharper disable once LoopCanBeConvertedToQuery
            foreach (string file in files)
            {
                var parser = new JSParser(File.ReadAllText(file)) { FileContext = file };
                var block = parser.Parse(new CodeSettings
                {
                    EvalTreatment = EvalTreatment.MakeImmediateSafe,
                    PreserveImportantComments = false
                });
                if (block != null)
                {
                    blocks.Add(block);
                }
            }

            Block fst = blocks[0];
            for (int i = 1; i < blocks.Count; i++)
            {
                fst.Append(blocks[i]);
            }

            string sequenceCode = fst.ToCode();
            var minifier = new Minifier();
            string compiled = minifier.MinifyJavaScript(
                sequenceCode,
                new CodeSettings
                {
                    EvalTreatment = EvalTreatment.MakeImmediateSafe,
                    PreserveImportantComments = false
                });
            return compiled;
        }
开发者ID:2xmax,项目名称:System.Web.StaticOptimization,代码行数:35,代码来源:MicrosoftAjaxScriptBundleCompiler.cs

示例6: ExtractCore

        public static void ExtractCore(Translator translatorInstance, string outputPath, bool nodebug = false)
        {
            var clrPath = translatorInstance.BridgeLocation;
            var assembly = System.Reflection.Assembly.UnsafeLoadFrom(clrPath);

            // We can only have Beautified, Minified or Both, so this test has inverted logic:
            // output beautified if not minified only == (output beautified or output both)
            if (translatorInstance.AssemblyInfo.OutputFormatting != JavaScriptOutputType.Minified)
            {
                ExtractResourceAndWriteToFile(outputPath, assembly, "Bridge.Resources.bridge.js", "bridge.js");
            }

            if (translatorInstance.AssemblyInfo.GenerateTypeScript)
            {
                ExtractResourceAndWriteToFile(outputPath, assembly, "Bridge.Resources.bridge.d.ts", "bridge.d.ts");
            }

            // Like above test: output minified if not beautified only == (out minified or out both)
            if (translatorInstance.AssemblyInfo.OutputFormatting != JavaScriptOutputType.Formatted)
            {
                if (!nodebug)
                {
                    ExtractResourceAndWriteToFile(outputPath, assembly, "Bridge.Resources.bridge.js", "bridge.min.js", (reader) => { var minifier = new Minifier(); return minifier.MinifyJavaScript(reader.ReadToEnd(), new CodeSettings { TermSemicolons = true }); });
                }
            }
        }
开发者ID:fabriciomurta,项目名称:BridgeUnified,代码行数:26,代码来源:Translator.cs

示例7: Minify

    /// <summary>
    /// Minifies the specified JavaScript.
    /// </summary>
    /// <param name="resource">The JavaScript to minify.</param>
    /// <returns>The minified JavaScript, if minification was successful; otherwise, the original JavaScript with minification errors appended at the end.</returns>
    public string Minify(string resource)
    {
        if (String.IsNullOrEmpty(resource))
        {
            return resource;
        }

        var settings = new CodeSettings
        {
            AllowEmbeddedAspNetBlocks = false,
            EvalTreatment = EvalTreatment.MakeAllSafe
        };
        var minifier = new Minifier();
        try
        {
            resource = minifier.MinifyJavaScript(resource, settings);
        }
        catch
        {
            var minificationErrors = String.Join(Environment.NewLine, minifier.Errors);
            resource = AppendMinificationErrors(resource, minificationErrors);

            if (mLogErrors)
            {
                CoreServices.EventLog.LogEvent("W", "Resource minification", "JavaScriptMinificationFailed", minificationErrors);
            }
        }

        return resource;
    }
开发者ID:kbuck21991,项目名称:kentico-blank-project,代码行数:35,代码来源:AjaxJavaScriptMinifier.cs

示例8: CompileAsync

	    /// <summary>
	    /// (Awaitable) Compiles content with the give configuration (files and minify flag).
	    /// </summary>
	    /// <param name="content">Content to Compile</param>
	    /// <param name="minify"></param>
	    /// <returns>string with compiled content</returns>
	    public Task<string> CompileAsync(string content, bool minify)
	    {
	        if (!minify)
	            return Task.FromResult(content);

			var minifier = new Minifier();
			return Task.FromResult(minifier.MinifyJavaScript(content));
		}
开发者ID:TerrificNet,项目名称:TerrificNet,代码行数:14,代码来源:JsAssetCompiler.cs

示例9: Minify

        public string Minify(string content)
        {
            var minifer = new Minifier();
            codeSettings = codeSettings ?? new CodeSettings();
            codeSettings.SetKnownGlobalNames(globalNames);

            return minifer.MinifyJavaScript(content, codeSettings);
        }
开发者ID:nuxleus,项目名称:SquishIt,代码行数:8,代码来源:MsMinifier.cs

示例10: Compress

 protected override string Compress(string source)
 {
     var minifier = new Minifier();
     var minified = minifier.MinifyJavaScript(source);
     if (minifier.Errors.Count > 0)
     {
         return source;
     }
     return minified;
 }
开发者ID:jlarsson,项目名称:MvcAssets,代码行数:10,代码来源:JsCompressor.cs

示例11: Minify

        public void Minify()
        {
            var minifer = new Minifier();
            var codeSettings = new CodeSettings();

            var content = _fileSystem.BundleFiles(_files);
            var minified =  minifer.MinifyJavaScript(content, codeSettings);

            _fileSystem.File.WriteAllText(_outputPath, minified);
        }
开发者ID:bdukes,项目名称:pretzel,代码行数:10,代码来源:JsMinifier.cs

示例12: Generate

 private static void Generate(string outputPath, bool minify, Minifier minifier, string js)
 {
     if (minify)
     {
         File.WriteAllText(outputPath, minifier.MinifyJavaScript(js));
     }
     else
     {
         File.WriteAllText(outputPath, js);
     }
 }
开发者ID:nightbob3,项目名称:SignalR,代码行数:11,代码来源:Program.cs

示例13: Minify

 public string Minify(string source)
 {
     CodeSettings settings = new CodeSettings
     {
         PreserveImportantComments = false,
         PreserveFunctionNames = true
     };
     Minifier doMin = new Minifier();
     string mind = doMin.MinifyJavaScript(source, settings);
     return mind;
 }
开发者ID:iondrimba,项目名称:musicbattl,代码行数:11,代码来源:Global.asax.cs

示例14: Process

        public override void Process(BundleContext context, BundleResponse response)
        {
            response.ContentType = ContentType.JavaScript;

            if (context.HttpContext.IsDebuggingEnabled)
            {
                return;
            }

            var minifier = new Minifier();
            response.Content = minifier.MinifyJavaScript(response.Content);
        }
开发者ID:philipproplesch,项目名称:Web.Optimization,代码行数:12,代码来源:AjaxMinJsMinify.cs

示例15: ProcessRequest

        public void ProcessRequest(HttpContext context)
        {
            _context = context;

            Map("~/Client/routes/", BuildName);
            Map("~/Client/controls/", file => String.Format("controls/{0}", Path.GetFileNameWithoutExtension(file)));

            var minifier = new Minifier();
            context.Response.ContentType = "text/javascript";
            var content = minifier.MinifyJavaScript(_builder.ToString());
            context.Response.Write(minifier.ErrorList.Any() ? _builder.ToString() : content);
            context.Response.End();
        }
开发者ID:Myslik,项目名称:opencat,代码行数:13,代码来源:TemplateRouter.cs


注:本文中的Microsoft.Ajax.Utilities.Minifier.MinifyJavaScript方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。