简体   繁体   English

Maven YUI Compressor:聚合后压缩

[英]Maven YUI Compressor: compress after aggregation

Can I setup Maven YUI Compressor for compression files after aggregation, because I want to exclude "sources" directory, which contain files for aggregation and then compress aggregated files. 我可以为聚合后的压缩文件设置Maven YUI Compressor,因为我想排除“ sources”目录,该目录包含用于聚合的文件,然后压缩聚合的文件。

For example I have some .js-files inside of /js/sources/mylib/ and all this files merged into one file /js/mylib.js while yui-compressor aggregation stage. 例如,我在/ js / sources / mylib /中有一些.js文件,在yui-compressor聚合阶段,所有这些文件都合并为一个文件/js/mylib.js In pom.xml I configure yui-compressor to exclude whole /js/sources/ and compress files only within /js library, but yui-compressor execute "compress" goal before aggregation, so I have uncompressed merged files. 在pom.xml中,我将yui-compressor配置为排除整个/ js / sources /并仅在/ js库中压缩文件,但是yui-compressor在聚合之前执行“压缩”目标,因此,我有未压缩的合并文件。 And I need to fix this somehow 我需要以某种方式解决此问题

Can we turn it around and say: Aggregate after compression? 我们可以绕开说:压缩后聚合吗? If so, I had the same issue and with the following it worked out for me. 如果是这样,我有同样的问题,下面的问题对我来说是可行的。

The trick seemed to be to put the output file in the target dir instead of in the source. 技巧似乎是将输出文件放在目标目录而不是源目录中。 That way you can include files that got minified in the aggregation. 这样一来,您就可以包含已在聚合中缩小的文件。

Files that were already minified I then approach through the basedir var. 然后,已缩小的文件将通过baseir var处理。

  <executions>
    <execution>
      <goals>
        <goal>compress</goal>
      </goals>
    </execution>
  </executions>        
  <configuration>
    <excludes>
        <exclude>**/*-min.js</exclude>
        <exclude>**/*.min.js</exclude>
        <exclude>**/*.css</exclude>
    </excludes>
    <removeIncluded>false</removeIncluded>
    <jswarn>false</jswarn>
    <aggregations>
        <aggregation>
          <insertNewLine>true</insertNewLine>
          <removeIncluded>false</removeIncluded>
          <includes>
              <!-- these exist only in target dir. the original was json2.js & bootstrap.tabs.js -->
              <include>**/bootstrap-tabs-min.js</include>
              <include>**/json2-min.js</include>
              <!-- use originals for the ones already minified -->
              <include>${basedir}/src/main/webapp/js/backbone-min.js</include>
          </includes>
          <output>${project.build.directory}/${project.build.finalName}/js/test.js</output>
        </aggregation>
    </aggregations>
  </configuration>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM