Automate Eclipse “Yui Compressor…”

前端 未结 4 1225
既然无缘
既然无缘 2021-01-14 00:17

Eclipse PDT has this handy built-in Yui Compressor in the context menu for files. But when building a webapp that uses multiple such files,

4条回答
  •  长发绾君心
    2021-01-14 00:57

    I would like to improve the answer of megre (https://stackoverflow.com/a/53678752/760777). His solution works, but can be improved. All credits to him though.

    In step 2: Change the location of the batch file into ${project_loc}\build\minify.bat Place your batch file "minify.bat" in a subfolder "build" in your project folder. Also change the arguments from "$resource_loc $project_loc" to "${project_loc}".

    If that does not work for you try "$project_loc". Different versions of Eclipse seem to use different variables.

    See screenshot:

    I changed the batch file completely:

    @ECHO OFF
    
    REM Note: There is a bug in yuicompressor 2.4.8 causing yuicompressor not te be accessible 
    REM       see https://stackoverflow.com/a/19339287/760777
    
    SET yui="C:\Program Files (x86)\yuicompressor\yuicompressor-2.4.7.jar"
    SET cssFolder=%1\css
    SET jsFolder=%1\js
    
    IF EXIST %cssFolder% (
      ECHO Processing folder "%cssFolder%" ... 
      CD %cssFolder%
      MKDIR min 2>NUL
      FOR %%f IN (*.css) DO (
        ECHO Minifying "%%~ff"
        java -jar %yui% %%f -o min\%%f
      )
    ) ELSE (
      ECHO %cssFolder% does not exist. Put your css files in a subfolder "css" in the current project folder 
    )
    
    IF EXIST %jsFolder% (
      ECHO Processing folder "%jsFolder%" ... 
      CD %jsFolder%
      MKDIR min 2>NUL
      FOR %%f IN (*.js) DO (
        ECHO Minifying "%%~ff"
        java -jar %yui% %%f -o min\%%f
      ) 
    ) ELSE (
      ECHO %jsFolder% does not exist. Put your js files in a sub folder "js" in the current project folder 
    )
    

    Probably unnecessary to say, but to use the minified files, you have to modify the references in your HTML / PHP files accordingly.

提交回复
热议问题