开发者

How to Improve this Visual Studio Post-Build Event that is using ajaxmin.exe

开发者 https://www.devze.com 2023-01-22 15:42 出处:网络
I am currently using Visual Studio 2010 post-build event to minify my JavaScript files.The problem is every time I add a 开发者_开发技巧new JavaScript file I have to update the post build event.What I

I am currently using Visual Studio 2010 post-build event to minify my JavaScript files. The problem is every time I add a 开发者_开发技巧new JavaScript file I have to update the post build event. What I want to do is make the script a bit more flexible.

Directory structure:

\Scripts\

  • Script1.debug.js
  • Script2.debug.js
  • Script3.debug.js

Here is my script's current state:

ajaxmin.exe "$(ProjectDir)Scripts\Script1.debug.js" -out "$(ProjectDir)Scripts\Script1.js" -clobber
ajaxmin.exe "$(ProjectDir)Scripts\Script2.debug.js" -out "$(ProjectDir)Scripts\Script2.js" -clobber
ajaxmin.exe "$(ProjectDir)Scripts\Script3.debug.js" -out "$(ProjectDir)Scripts\Script3.js" -clobber

I want this script to find every *.debug.js file minify it and output it to *.js. How do I achieve this?

Script1.debug.js --> Script1.js

Script2.debug.js --> Script2.js

Script3.debug.js --> Script3.js


Don't use a post build event. After installing the tool, an MSBuild task was added that runs the minifier automatically for a .js file in your project. You need a bit of minor surgery to the project file. The details are explained in this blog post.


Try this:

@echo off

for /r "js\" %%i IN (*.js) do (
    call :Sub %%~fi
)

:Sub
set debug=%*
set release=%debug:.debug=%
AjaxMin.exe -hc "%debug%" -o "%release%" -clobber

Find all javascript (*.js) files in folder "js\" then remove ".debug" from filename (actually replace it with null string) and run AjaxMin


Create a batch script file to do the task and call the batch file from your PostBuild event.

0

精彩评论

暂无评论...
验证码 换一张
取 消