如何使用yuicompressor-maven-plugin让maven与缩小的文件建立战争 [英] How to get maven to build a war with minified files using yuicompressor-maven-plugin

查看:112
本文介绍了如何使用yuicompressor-maven-plugin让maven与缩小的文件建立战争的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在尝试一些我认为相当简单的东西,我基本上希望maven在构建战争之前为我缩小所有js和css文件。我的插件如下所示:

So I'm trying something I thought would be rather simple, I basically want maven to minify all my js and css files for me before building a war. My plugins look like this:

         <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <extensions>true</extensions>
            <version>1.0.0</version>
            <configuration>
                <manifestLocation>META-INF</manifestLocation>
                <instructions>
                    <Export-Package>!test.impl,test*</Export-Package>
                    <Import-Package>*</Import-Package>
                    <!--
                       add ,plugin.xml if it's present i.e.
                       src/main/resources,plugin.xml
                    -->
                    <Include-Resource>src/main/resources</Include-Resource>
                </instructions>
            </configuration>
        </plugin>

        <plugin>
            <groupId>net.alchim31.maven</groupId>
            <artifactId>yuicompressor-maven-plugin</artifactId>
            <version>1.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>compress</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <nosuffix>true</nosuffix>
            </configuration>
        </plugin>

问题是YUI插件确实正确缩小了文件,但就在战争构建之前看起来它复制了我的主源目录中的所有文件,因此消除了YUI插件所做的更改。

The problem is that the YUI plugin does correctly minify the files, but just before the war is built it looks like it copies over all the files from my main source directory and thus wipes out the changes the YUI plugin had done.

我正在通过以下方式调用maven: mvn编译战争:战争。我已经玩了一段时间不同的设置,但到目前为止我还没有找到解决方法。

I'm calling maven by the following: mvn compile war:war. I've been playing around for awhile with different settings, but so far I haven't found a way around this.

战争结束后我想要的是什么已经从src目录复制了它需要的文件,它会运行YUI插件,但是我尝试了YUI插件上所有阶段的排列,但这似乎没有任何区别。

What I would like is for just after the war has copied over the files it needed from the src directory it would run the YUI plugin, but I tried all the permutations of phases on the YUI plugin, but that didn't seem to make any difference.

我已经google了一下,但是到目前为止我所读到的几乎所有内容似乎都表明我应该像我一样放弃YUI插件并且一切都应该神奇地工作。到目前为止,我似乎没有找到魔法。

I've googled around, but pretty much everything I've read so far seems to indiciate that I should just need to drop the YUI plugin in there like I have and everything should magically work. So far I haven't seem to have found the magic.

推荐答案

上面的配置是运行压缩机的在进程资源阶段,然后包阶段用原始阶段覆盖这些文件。

What happens is that the config above is running the compressor on the process-resources phase, but then the package phase overwrites these files with the original ones.

通过将阶段更改为包,它应该工作:

By changing the phase to package, it should work:

<execution>
    <phase>package</phase>
    <goals>
        <goal>compress</goal>
    </goals>

现在压缩完成了复制到目标的文件,以便构建WAR内容。

Now the compression is done after the files where copied to target in order to build the WAR content.

发生这种情况的原因是,只压缩文件而不连接它们或用后缀重命名它们不是插件最常见的用例。

The reason why this is happening is that only compressing files without concatenating them or renaming them with a suffix is not the most common use case for the plugin.

通常我们想要将文件压缩并连接到一个文件中,并给它一个新名称。

Normally we want to compress and concatenate files into only one file, and give it a new name.

新名称是通常类似于originalname-min.css / original.name-min.js,其中.min是后缀,因此删除上面配置中的nosuffix选项也可以。

The new name is usually something like originalname-min.css / original.name-min.js where .min is the suffix, so removing the nosuffix option on the config above would also work.

编辑:日志示例

[INFO] --- yuicompressor-maven-plugin:1.1:compress (default) @ yui-compressor-test -
[INFO] prettify.css (817b) -> prettify.css (617b)[75%]
[INFO] total input (1510b) -> output (1134b)[75%]

这篇关于如何使用yuicompressor-maven-plugin让maven与缩小的文件建立战争的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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