想在构建时自动压缩和合并指定的 js 文件,免得每次改了后手动压缩,但是输出的文件却没有压缩、混淆代码,试过把 aggregations
去掉但什么也没发生,输出如果指向 ${project.build.directory}/${project.build.finalName}
下面则在清理后会报找不到文件,即使 phase
改成 prepare-package
也不行。有一点猜测可能引起问题的地方在于我的 webapp
目录是特别配置的,不是默认位置,但试了设置 sourceDirectory
和 outputDirecotry
无效。pom.xml 中配置如下:
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.5.1</version>
<executions>
<execution>
<goals>
<goal>compress</goal>
</goals>
</execution>
</executions>
<configuration>
<encoding>UTF-8</encoding>
<jswarn>false</jswarn>
<suffix>.min</suffix>
<excludes>
<exclude>**/*.min.*</exclude>
<exclude>**/*-min.*</exclude>
</excludes>
<aggregations>
<aggregation>
<output>${basedir}/web/static/assets/hongscore.js</output>
<inputDir>${basedir}/web/static/assets/src</inputDir>
<includes>
<include>hongscore.js</include>
<include>hongscore-form.js</include>
<include>hongscore-list.js</include>
<include>hongscore-tree.js</include>
<include>hongscore-fork.js</include>
<include>hongscore-file.js</include>
<include>hongscore-date.js</include>
</includes>
<removeIncluded>false</removeIncluded>
<insertNewLine>true</insertNewLine>
</aggregation>
</aggregations>
</configuration>
</plugin>
PHP中文网2017-04-18 10:49:42
맙소사, 수정된 webapp 디렉토리를 가리키도록 warSourceDirectory
을 구성하면 됩니다. 저는 질문을 작성할 때 무엇을 시도해야 할지 기억하고 있었는데, war 패키지의 다른 위치를 구성하는 한, 모든 것이 괜찮을 것입니다.