在构建服务器上将 Google Closure 编译器与 MS Build 集成
我正在研究缩小 javascript 文件的方法,作为 CI 流程的一部分,以便我们可以在开发中使用未缩小的文件,并在部署到临时服务器和实时服务器时自动压缩它们。
这是针对 ASP.NET 站点的;我们使用 Hudson 作为构建服务器。
我对 Google Closure 编译器很感兴趣,并且遇到了这个 .Net MSBuild Google Closure 编译器Task,但似乎使用得不是很广泛。是否有更好的选项可与 MSBuild 一起使用,使用 Closure 或替代缩小工具?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我们在基于 .NET 的项目中使用 Closure Compiler 一段时间了。
最初,我们使用一个简单的 MSBuild .proj 文件,它直接调用 Python 脚本。例如,我们将使用如下内容来制作 deps.js:
实际构建更复杂,但仍然相对简单(假设您精通 MSBuild)。我们只是为脚本调用的每个相关部分使用了不同类型的项目组。
这很简单,我们不需要费心去寻找任务,或者尝试投资构建我们自己的任务。 Closure 是一个快速发展的项目,因此最好不要过度依赖任何第三方构建系统,尤其是那些看起来没有维护的系统(您链接的任务)。
现在,我一直用过去时态说话,因为我们的构建系统已经迁移了一些。具体来说,随着我们的项目不断增长,将脚本代码的不同部分划分为模块变得越来越重要。使用开箱即用的闭包脚本来执行此操作将是一场噩梦。因此,我们决定转向 plovr (http://plovr.com/),这使得将代码划分为模块变得非常简单。 plovr 的维护非常活跃,由 Michael Bolin 创建,他确实写了一本关于 Closure 的书(也强烈推荐)。
我们仍然使用相同的 MSBuild 文件来包装它。基本上,我们在项目组中定义的内容会移动到 plovr-config.js 文件中,并且调用也变得更加简单:
plovr 支持其他一些很酷的功能,例如大小报告和模块图,但甚至如果没有这些,我们对当前的设置非常非常满意。
We've been using Closure Compiler for some time now in a .NET-based project.
Initially, we used a simple MSBuild .proj file which directly invoked the Python scripts. For example, we would make deps.js with something like the following:
The actual build was more complex, but still relatively straightforward (assuming you're MSBuild savvy). We simply used different types of item groups for each relevant part of the script invocation.
This was simple enough that we didn't bother looking for a task, or trying to invest in building our own. Closure is quite a fast moving project, so it's good to be in a situation where you're not overly dependent upon any third party build systems, especially one that looks to be unmaintained (the task you linked).
Now, I've been speaking in past tense because our build system has migrated a bit. Specifically, as our project kept growing it became increasingly important to partition different parts of our script code into modules. Doing this with the out-of-the-box Closure scripts would be quite a nightmare. Thus, we decided to move to plovr (http://plovr.com/), which makes partitioning code into modules very simple. plovr is very actively maintained and was created by Michael Bolin, who literally wrote the book on Closure (also highly recommended).
We still wrap this using the same MSBuild file. Basically, the stuff that we were defining in the item groups moves to a plovr-config.js file, and the invocation becomes much simpler as well:
There are some other cool features supported by plovr, like size reports and module graphs, but even without those we're very, very pleased with our current setup.
最明显的选择是 YUI Compressor,它稳定可靠。
它有一个 .Net 端口: Yahoo! UI 库:.Net 的 YUI 压缩器
附带了 mbsbuild 任务。
另外,使用原始(Java)是 就像使用
Exec
任务一样简单,唯一的缺点是它具有java依赖性。The most obvious choice is YUI Compressor, it's stable and reliable.
It has a .Net port: Yahoo! UI Library: YUI Compressor for .Net
The ships with an mbsbuild task.
Also, using the original (Java) is just as easy using
Exec
task, the only drawback is that it has java dependency.有 SquishIt 详细信息 这是一个运行时压缩器,但做得相当好。
There's SquishIt Details which is a runtime compressor, but done quite well.
您应该看到我在 将 Microsoft AJAX Minifier 与 Visual Studio 2010 一键发布结合使用。您应该能够使用此处的详细信息来解决您的问题。
You should see a very similar question that I answered at Using Microsoft AJAX Minifier with Visual Studio 2010 1-click publish. You should be able to use the details there to solve your problems here.