如何改进使用 ajaxmin.exe 的 Visual Studio 生成后事件

发布于 2024-09-29 13:54:26 字数 801 浏览 0 评论 0原文

我目前正在使用 Visual Studio 2010 构建后事件来缩小我的 JavaScript 文件。问题是每次我添加新的 JavaScript 文件时,我都必须更新构建后事件。我想做的就是让脚本更加灵活一点。

目录结构:

\脚本\

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

这是我的脚本的当前状态:

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

我希望此脚本找到每个 *.debug.js 文件,缩小并输出它到 *.js。我该如何实现这一目标?

Script1.debug.js --> Script1.js
Script2.debug.js --> Script2.js
Script3.debug.js --> Script3.js

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夏末染殇 2024-10-06 13:54:26

不要使用构建后事件。安装该工具后,添加了一个 MSBuild 任务,该任务会自动为项目中的 .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.

ˇ宁静的妩媚 2024-10-06 13:54:26

试试这个:

@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

在文件夹“js\”中查找所有 javascript (*.js) 文件,然后从文件名中删除“.debug”(实际上用空字符串替换它)并运行 AjaxMin

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

我要还你自由 2024-10-06 13:54:26

创建批处理脚本文件来执行任务并从 PostBuild 事件调用批处理文件。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文