使用YUI Compressor Maven Mojo缩小javascript [英] Usage of YUI Compressor Maven Mojo minifying javascript

查看:110
本文介绍了使用YUI Compressor Maven Mojo缩小javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用maven编译struts2项目。我正在尝试缩小位于不同位置的javascript文件。

I work on a struts2 project using maven to compile. I am trying to minify the javascript files, which are located in different locations.

<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的定义)。

I assume that by doing this, all js files will be minified and replaced the original file in the production war file (according to definition for nosuffix).

但似乎并非如此。我怎么能搞这个?

However it doesn't seem to be the case. How can I acheve this?

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

Secondly, if I choose to use the one with the suffix, I assume I have to manually change the scripts reference in my jsp files is that correct? If so, how do I set it so that it will remove the original without the suffix?

谢谢。

推荐答案

我找到了工作解决方案这里。基本上你需要将以下内容放入pom.xml(仅替换src / main / webapp文件夹中js和css文件的路径):

I have found working solution here. Basically you need to place the following into you pom.xml (replacing only the path to you js and css files inside src/main/webapp folder):

    <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>

这篇关于使用YUI Compressor Maven Mojo缩小javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆