使用Maven进行JavaScript压缩的工作流程 [英] JavaScript minification workflow with Maven

查看:122
本文介绍了使用Maven进行JavaScript压缩的工作流程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有任何将现代JavaScript构建工作流"集成到生成WAR工件的Maven构建中的最佳实践".

I am wondering about any "best practices" to integrate a "modern JavaScript build workflow" into a Maven build that produces a WAR artifact.

我发现了一些可以处理串联和缩小的Maven插件:

I have found several maven plugins that handle concatenation and minification:

  • WRO4J: https://code.google.com/p/wro4j/wiki/MavenPlugin
  • Minify Maven Plugin: https://github.com/samaxes/minify-maven-plugin
  • YUI: http://alchim.sourceforge.net/yuicompressor-maven-plugin/

但是,我仍然缺少它们如何适合完整的构建工作流,因为我认为必须启用和禁用串联/最小化:

However I am still missing how they fit into a full build workflow, since I think it is mandatory to be able to switch concatenation/minification on and off:

对于开发,我想构建一个不包含级联/最小化资源的WAR,以便我可以方便地进行调试.对于生产版本,我想产生一个包含级联/最小化资源的WAR.

For development I want to build a WAR that does not contain the concatenated/minified resources so that I can conveniently debug. For a production build I want to produce a WAR that contains the concatenated/minified resources.

此外,对于生产版本,我还必须重写" html中的脚本URL,以指向脚本的串联/最小化版本.

Additionally for the production build I then have to "rewrite" the script URLs in my html to point to the concatenate/minified version(s) of the script(s).

在JavaScript世界中,我将Grunt与不同的grunt任务(uglify,usemin)结合使用以实现上述工作流程.如何在Maven构建中实现相同的目标?

In the JavaScript world I would use Grunt with different grunt tasks (uglify, usemin) to achieve the above workflow. How can I achieve the same in a Maven build?

推荐答案

自从您提到Grunt以来,您是否考虑过直接从Maven构建中调用Grunt任务?这不是一个完美的解决方案,但它为您提供了更多选择,而无需依赖Maven插件. http://addyosmani.com/blog/making-maven-grunt/

Since you mentioned Grunt, have you considered calling Grunt tasks directly from your Maven build? It's not a perfect solution, but it gives you some more options without relying on Maven plugins. http://addyosmani.com/blog/making-maven-grunt/

此外,这个SO主题: Javascript Web应用程序和Java服务器,全部在Maven中构建还是将Grunt用于Web应用程序?

Also, this SO topic: Javascript web app and Java server, build all in Maven or use Grunt for web app?

这篇关于使用Maven进行JavaScript压缩的工作流程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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