VS2010自动重建缩小的.js文件/ .css文件 [英] VS2010 Automatically rebuild minified .js/.css files

查看:211
本文介绍了VS2010自动重建缩小的.js文件/ .css文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题



我一直在试图整合JavaScript和CSS文件在我们的VS2010(.NET 4)项目缩小。从我听到的,.NET 4.5和VS2012将有微小建设到编辑器中,所以这将是为设置标志,将工作一样简单。不幸的是,我们都在VS2010(.NET 4.0)窗台。

Problem:


I have been trying to integrate minification of javascript and css files in our VS2010 (.net 4.) projects. From what I hear, .net 4.5 and VS2012 will have minification build into the editor, so it will be as easy as setting a flag it will work. Unfortunately we are sill on VS2010 (.net 4.0).

让我解释什么,我想做什么,我不想做的事。

Let me explain what I want to do and what I dont want to do.

我不想做班/ config文件(S)/等大的设置只是来缩小,因为所有的东西都会有我们的构建机器上加载,甚至构建XML文件可能必须修改,使它工作。此外,一旦我们去vs2012和.net 4.5所有这些CONFIGS /班/等将不得不放弃,因为vs2012将在功能构建。

I dont want to do big setups with classes/config file(s)/etc just to minify because all that stuff will have to be loaded on our build machine and even the build xml files might have to be modifies to make it work. Also, once we go to vs2012 and .net 4.5 all these configs/classes/etc will have to be discarded because vs2012 will have the build in functionality.

下面是我认为可能是最好的选择。由于我使用ScriptManager而且它已经可以拉动无论是.debug.js(非精缩)或者基于构建类型的.js(缩小的)脚本,似乎所有我需要做的是有某种( pre?)建设活动,将重新打造一个非缩小的js文件到一个缩小的之一。显然,生成事件必须调用哪些必须被本地计算机上安装一个minication模组(YUI的COM pressor看起来很不错)。该模块将更新缩小的.js文件。

Here is what I think might be the best option. Since I am using the ScriptManager and it can already pull either a .debug.js (non-minified) or a .js (minified) script based on the build type, it seems all i need to do is to have some sort of (pre?) build event that will re-build a non-minified .js file into a minified one. Obviously the build event will have to call a minication module which would have to be installed on local computer (the YUI Compressor seems very nice). The module would update the minified .js file.

我一直在阅读这一点,但我得到一点点丧失。有很多的,我不希望添加第三方工具有一堆的设置和课程。
有没有人做类似的,因为我对解释的东西吗?
如果没有什么是下一个最好的简单的解决方案?

I have been reading about this, but I am getting a little bit lost. There are a lot of third party tools with bunch of setup and classes which I do not want to add. Did anyone do something similar as I explained about? If not what is the next best simple solution?

(顺便说一句,如果你会说移动到VS2012 / 4.5,那不是在这一点上我们的一个解决方案)

(By the way, if you are going to say move to VS2012/4.5, thats not a solution for us at this point)

解决方案



感谢您的 Parv夏尔马你的答案。

我只是想解释我做了什么,这样它可以帮助别人的未来。

I would just like to explain what I did so that it may help someone in the future.


  1. 我安装的是微软的Ajax Minifier

  2. 创建一个批处理文件添加到minifer PATH环境变量:SETX路径/ M%PATH%; C:\\ Program Files文件\\微软\\微软的Ajax Minifier

  3. 增加了以下pre-生成事件到我的项目:
    ajaxmin $(PROJECTDIR)的script.js退房手续$(PROJECTDIR)Script.min.js -clobber

如果Script.min.js不存在,它将被构建事件创建,但它不会被添加到项目(不知道怎么做,通过事件)。

If Script.min.js does not exist, it will be created by the build event, but it will not be added to the project (not sure how to do that through the events).

当您添加一个新的脚本文件,mynewscript.js,只需创建一个空白的第二个文件调用mynewscript.min.js并为它添加一个pre-生成事件。

When you add a new script file, mynewscript.js, just create a second blank file called mynewscript.min.js and add an pre-build event for it.

使用这种方法,你必须做的构建机器的唯一事情是运行微软的Ajax Minifier安装包和批处理文件。这就是它一切将是你的pre-建设活动的一部分。

Using this approach the only thing you have to do to the build machine is run the Microsoft Ajax Minifier setup package and the batch file. Thats it everything else will be part of your pre-build events.

推荐答案

您正在寻找的东西可能是这个结果
HTTP://ajaxmin.$c$cplex.com/documentation 结果
通过使用该你将能够使用此第三方工具作为minifier结果
下载该工具后,你有2个选项结果
1.编辑MSBUILD文件,包括建设的JS按照生成事件结果
或者2.以这种方式,您将能够来缩小每当你想要的,就像我们做F5或CNTRL-Shift-B键

what you are looking for is probably this
http://ajaxmin.codeplex.com/documentation
by using this you would be able to use this third party tool as the minifier
after downloading the tool you have 2 options
1. edit the MSBUILD file to include building the js as per build event
OR 2. to attach this tool to VS and assign a key compbination to it.. this way you would be able to minify whenever you want just like we do F5 OR Cntrl-Shift-B

结果附加到VS容易只是向外部工具,并在工具菜单,并使用所需PARAMS添加此工具


Attaching to VS is easy just to to external tools and in the Tools menu and add this tool with the required params

这篇关于VS2010自动重建缩小的.js文件/ .css文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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