我在做一个struts2项目,使用maven来编译。我正在尝试缩小位于不同位置的 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 文件都将被缩小并替换生产 war 文件中的原始文件(根据 nosuffix 的定义)。
但事实似乎并非如此。我怎样才能做到这一点?
其次,如果我选择使用带有后缀的后缀,我认为我必须手动更改 jsp 文件中的脚本引用,这是正确的吗?如果是这样,我该如何设置才能删除不带后缀的原件?
Thanks.
我找到了工作解决方案here https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwiki-platform-web/pom.xml。基本上,您需要将以下内容放入 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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)