2012-08-01 100 views
2

我爲maven使用yui-compressor插件,似乎無法使其壓縮。所有js文件的附加工作正常。它不會刪除註釋,換行符,也不會縮小js(即將var var myVar轉換爲var a)。我的配置有問題嗎?Maven&yui-compressor插件問題

<plugin> 
        <groupId>net.alchim31.maven</groupId> 
        <artifactId>yuicompressor-maven-plugin</artifactId> 
        <version>1.1</version> 
        <executions> 
         <execution> 
          <goals> 
           <goal>compress</goal> 
          </goals> 
          <configuration> 
           <jswarn>false</jswarn> 
           <disableOptimizations>false</disableOptimizations> 
           <insertNewLine>false</insertNewLine> 
           <preserveAllSemiColons>false</preserveAllSemiColons> 
           <aggregations> 
            <aggregation> 
             <removeIncluded>true</removeIncluded> 
             <!-- insert new line after each concatenation (default: false) --> 
             <output>${project.build.directory}/${project.build.finalName}/WEB-INF/scripts/all.js</output> 
             <!-- files to include, path relative to output's directory or absolute 
              path --> 
             <!--inputDir>base directory for non absolute includes, default to 
              parent dir of output</inputDir --> 
             <includes> 
              <include>${basedir}/src/main/webapp/WEB-INF/scripts/underscore.js</include> 
<include>${basedir}/src/main/webapp/WEB-INF/scripts/backbone.dev.js</include> 
<include>${basedir}/src/main/webapp/WEB-INF/scripts/modernizr.custom.83543.js</include> 
<include>${basedir}/src/main/webapp/WEB-INF/scripts/jquery.slider.min.js</include> 
<include>${basedir}/src/main/webapp/WEB-INF/scripts/myApp.js</include> 
             </includes> 
             <!-- files to exclude, path relative to output's directory <excludes> 
              <exclude>**/*.pack.js</exclude> <exclude>**/compressed.css</exclude> </excludes> --> 
            </aggregation> 
           </aggregations> 
           <includes> 
            <include>${basedir}/src/main/webapp/WEB-INF/scripts/*.js</include> 
           </includes> 
           <excludes> 
            <exclude>${basedir}/src/main/webapp/WEB-INF/scripts/*min*.js</exclude> 
            <exclude>${basedir}/src/main/webapp/WEB-INF/scripts/underscore.js</exclude> 
            <exclude>${basedir}/src/main/webapp/WEB-INF/scripts/backbone.js</exclude> 
            <exclude>${basedir}/src/main/webapp/WEB-INF/scripts/modernizr*.js</exclude> 
            <exclude>${basedir}/src/main/webapp/WEB-INF/scripts/*fancybox*.js</exclude> 
            <exclude>${basedir}/src/main/webapp/WEB-INF/scripts/jquery.easing*.js</exclude> 
           </excludes> 
          </configuration> 
         </execution> 
        </executions> 
       </plugin> 

回答

1

我想清楚發生了什麼事情。實際上,出現了一些問題:首先,整個配置塊需要與執行塊相鄰,而不是在其內部。其次,insertNewLine選項需要位於聚合包中。第三,沒有被刪除的評論是/ *! * /註釋,通常包含許可信息和yui-compressor不會刪除。第四,也是最重要的一點,myApp.js中有一個eval,它被認爲是「邪惡」,並且停止了yui壓縮器的壓縮。

希望這有助於人們!

0

我建議你使用jshint插件和lint你的js代碼作爲上一步壓縮js。如果檢測到eval,結束錯誤的逗號等,則在嘗試壓縮之前,您的Maven構建失敗。

 <plugin> 
      <groupId>com.cj.jshintmojo</groupId> 
      <artifactId>jshint-maven-plugin</artifactId> 
      <version>1.6.0</version> 
      <executions> 
       <execution> 
        <phase>process-resources</phase> 
        <goals> 
         <goal>lint</goal> 
        </goals> 
       </execution> 
      </executions> 
      <configuration> 
       <options>forin,sub,evil,latedef,eqnull</options> 
       <directories> 
        <directory>src/main/webapp/</directory> 
       </directories> 
       <excludes> 
        <exclude>src/main/webapp/extjs-4.2</exclude> 
       </excludes> 
       <reporter>jslint</reporter> 
       <reportFile>target/jshint.xml</reportFile> 
       <failOnError>true</failOnError> 
      </configuration> 
     </plugin> 
+0

這並沒有提供問題的答案。一旦你有足夠的[聲譽](http://stackoverflow.com/help/whats-reputation),你將可以在任何帖子上[評論](http://stackoverflow.com/help/privileges/comment)。另外檢查這[我可以做什麼,而不是](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-c​​an-i-do-instead )。 – thewaywewere 2017-06-02 06:33:15