我使用maven编译struts2项目。我正在尝试缩小位于不同位置的javascript文件。
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.3.0</version>
<executions>
<execution>
<goals>
<goal>compress</goal>
</goals>
</execution>
</executions>
<configuration>
<nosuffix>true</nosuffix>
</configuration>
</plugin>
我假设通过这样做,所有的js文件都将被缩小,并替换为生产战争文件中的原始文件(根据nosuffix的定义)。
然而,情况似乎并非如此。我怎样才能做到这一点?
其次,如果我选择使用带后缀的,我认为我必须手动更改jsp文件中的脚本引用,这是正确的吗?如果是,我该如何设置它,使其删除没有后缀的原始文件?
谢谢。
我在这里找到了有效的解决方案。基本上,您需要将以下内容放入pom.xml中(仅替换src/main/webapp文件夹中js和css文件的路径):
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<!-- Add minified resources -->
<resource>
<directory>${project.build.directory}/minimized</directory>
<targetPath>/</targetPath>
<filtering>false</filtering>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>compress</goal>
</goals>
</execution>
</executions>
<configuration>
<nosuffix>true</nosuffix>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!-- Javascript and CSS files compression -->
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.1</version>
<configuration>
<!-- Don't output in the default webapp location, since the war plugin will overwrite the files in there
with the original, uncompressed ones. -->
<webappDirectory>${project.build.directory}/minimized</webappDirectory>
<jswarn>false</jswarn>
<!-- Overwrite existing files -->
<nosuffix>true</nosuffix>
<includes>
<include>%path to your js and css files inside src/main/webapp%/**/*</include>
</includes>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>