java - Maven YUI Compressor,连接但不缩小(关闭压缩)

标签 java maven vaadin yui vaadin7

我正在处理一个遗留项目,它是一个 Vaadin 组件,它使用 Maven YUI 插件来缩小和连接 javascript 文件。有40个js文件。

YUI 插件正常工作,将 40 个 js 文件缩小并将它们连接成一个文件(然后在 Vaadin 中用 @javascript 引用)。

因为新功能的缩小开发很痛苦,但我不能删除 YUI 插件,因为那时我需要为所有 40 个 js 文件添加一个 @javascript 注释。

有没有办法让 YUI 聚合但缩小。我已经阅读了文档并尝试更改目标(即仅更改为 jslint),但如果我不使用 compress 目标,我似乎无法汇总。

我是不是漏掉了什么?

这是我的 YUI 配置:

<plugin>
  <groupId>net.alchim31.maven</groupId>
  <artifactId>yuicompressor-maven-plugin</artifactId>
  <version>1.5.1</version>
  <executions>
    <execution>
      <id>jslint</id>
      <goals>
        <goal>jslint</goal>
      </goals>
      <configuration>
      <includes>
        <include>**/*.js</include>
      </includes>
      <excludes>
        <exclude>**/VAADIN/js/*.js</exclude>
        <exclude>**/depends/*.js</exclude>
      </excludes>
      </configuration>
    </execution>
  <execution>
  <id>minify</id>
  <goals>
    <goal>compress</goal>
  </goals>
  <configuration>
  <nosuffix>true</nosuffix>
  <force>true</force>       
  <excludeWarSourceDirectory>true</excludeWarSourceDirectory>
  <linebreakpos>-1</linebreakpos>
  <aggregations>
    <aggregation>
      <inputDir>target/classes/[path]/components</inputDir>
      <removeIncluded>true</removeIncluded>
      <output>${project.build.directory}/classes/[path].js</output>
    <includes>
      <include>**/*.js</include>
      <include>**/Copyright.txt</include>
    </includes>
    <excludes>
      <exclude>**/depends/d3_3.4.6.js</exclude>
    </excludes>
    </aggregation>
  </aggregations>
  <includes>
    <include>**/*.js</include>
    <include>**/[project.name].css</include>
  </includes>
  <excludes>
    <exclude>**/depends/*.js</exclude>
  </excludes>
  </configuration>
  </execution>
  </executions>
</plugin>

N.b. 我也尝试过在 jslint 目标中使用聚合配置进行上述操作,但没有成功。

必须有一种方法来停止压缩(我知道 YUI 是一个压缩插件,但它还有其他功能(比如 lint)所以我假设你可以关闭压缩)。此外,Vaadin 的 @javascript 注释采用逗号分隔的 js 文件列表。我觉得加 40 太多了,但也许 @javascript 可以获取一个目录。 (虽然文档没有提到这一点)

最佳答案

决定回答这个我找到了一个解决方案,为任何找到它的人举办聚会,部分原因是它没有得到任何其他答案。

解决方案的灵感来自这个 answer有人问我需要什么的网站。 @Mady 指出了插件配置中的不同包含/排除

长话短说,您可以在 minifyer 中排除所有 .js 文件将它们包含在 agreegator 中:

<execution>
  <id>minify</id>
  <goals>
    <goal>compress</goal>
  </goals>                      
  <configuration>
    <nosuffix>true</nosuffix>
    <force>true</force>
    <excludeWarSourceDirectory>true</excludeWarSourceDirectory>
    <linebreakpos>-1</linebreakpos>
    <aggregations>
      <aggregation>
        <includes>
          <include>**/*.js</include> <!-- INCLUDES FOR CONCATENATION -->
        </includes>
      </aggregation>
    </aggregations>
    <excludes>
      <exclude>**/*.js</exclude> <!-- EXCLUDE ALL JS FROM MINIFICATION -->
    </excludes> 
  </configuration>
</execution>

关于java - Maven YUI Compressor,连接但不缩小(关闭压缩),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31557374/

相关文章:

java - 如何为 Filebeat 配置 JBoss JsonFormatter (WildFly 14)

java - 安装Ardor3D。我什至无法运行这些示例

maven - 如何输出 Maven 依赖项的简单列表

vaadin - 带有 vaadin 的 Web 组件和带有 svelte 的汇总 : Primary button ignores theme attribute

java - 在 Liferay 7 中创建和部署 Vaadin 7 Portlet

Vaadin 菜单栏上的监听器

java - 是否可以更改并非为支持依赖项注入(inject)而构建的闭源库中的错误类?

java - 自定义 Maven 原型(prototype) : default value for version not used

css - 为什么maven无法读取我的css和图片

java - 包括来自导入的 maven 库的依赖项