gpt4 book ai didi

javascript - YUI Compressor Maven Mojo 压缩 javascript 的使用

转载 作者:行者123 更新时间:2023-11-29 20:06:18 24 4
gpt4 key购买 nike

我在使用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 文件都将被缩小并替换生产 war 文件中的原始文件(根据 nosuffix 的定义)。

不过好像不是这样的。我怎样才能达到这个目的?

其次,如果我选择使用带有后缀的那个,我假设我必须手动更改我的 jsp 文件中的脚本引用,对吗?如果是这样,我该如何设置它以便删除没有后缀的原始文件?

谢谢。

最佳答案

我找到了可行的解决方案 here .基本上,您需要将以下内容放入 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>

关于javascript - YUI Compressor Maven Mojo 压缩 javascript 的使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11836599/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com