zoukankan      html  css  js  c++  java
  • C#调用jar包压缩js

    压缩库为google提供的 Closure Compiler

    https://developers.google.com/closure/compiler/?hl=zh-cn

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Diagnostics;
    
    namespace TestProcessDosCmd
    {
        class Program
        {
            static void Main(string[] args)
            {
    
                Process p = null;
                p = new Process();
                
                p.StartInfo.FileName = "cmd.exe";
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardInput = true;
                p.StartInfo.RedirectStandardOutput = false;
                p.StartInfo.RedirectStandardError = false;
                p.StartInfo.CreateNoWindow = false;
                p.Start();
    
                String sResult = string.Empty;
                string strCmd = "java -jar compiler.jar --help";
    
                //string strCmd = @"java -jar compiler.jar --js D:\DevSoft\Library\compiler-latest\js_name.js --js_output_file D:\DevSoft\Library\compiler-latest\js_name_compressed_prog.js";
    
                //不能源文件与目的文件放同一位置
                //string strCmd = @"java -jar compiler.jar --js D:\DevSoft\Library\compiler-latest\js_name_bak.js --js_output_file D:\DevSoft\Library\compiler-latest\js_name_bak.js";
                
                //string strCmd = "java -version";
                p.StandardInput.WriteLine(strCmd);
               
    
                //while (!p.StandardError.EndOfStream)
                //{
                //    sResult = p.StandardError.ReadLine();
                //    Console.WriteLine(sResult);
                //}
    
                //p.StandardInput.Flush();
    
                //while (!p.StandardOutput.EndOfStream)
                //{
                //    sResult = p.StandardOutput.ReadLine();
                //    Console.WriteLine(sResult);
                //}
                
                p.StandardInput.WriteLine("exit");
    
                p.WaitForExit();
                p.Close();
    
                Console.WriteLine("Press Any Key to exit.");
                Console.ReadKey();
            }
        }
    }
    

      

    from: https://developers.google.com/closure/compiler/docs/api-tutorial1?hl=zh-cn

    #!/usr/bin/python2.4
    
    import httplib, urllib, sys
    
    # Define the parameters for the POST request and encode them in
    # a URL-safe format.
    
    params = urllib.urlencode([
        ('js_code', sys.argv[1]),
        ('compilation_level', 'WHITESPACE_ONLY'),
        ('output_format', 'text'),
        ('output_info', 'compiled_code'),
      ])
    
    # Always use the following value for the Content-type header.
    headers = { "Content-type": "application/x-www-form-urlencoded" }
    conn = httplib.HTTPConnection('closure-compiler.appspot.com')
    conn.request('POST', '/compile', params, headers)
    response = conn.getresponse()
    data = response.read()
    print data
    conn.close
    

      

  • 相关阅读:
    第12-13周总结
    排球比赛计分规则
    我与计算机
    排球比赛计分规则-三层架构
    怎样成为一个高手 观后感
    最后一周冲刺
    本周psp(观众页面)
    本周psp(观众页面)
    本周工作计量
    本周总结
  • 原文地址:https://www.cnblogs.com/wucg/p/2399980.html
Copyright © 2011-2022 走看看