I’m not one for dumping all scripts into a single folder and calling it a day.
I want to create minified versions of scripts, yet not minify scripts that have already been minified by other processes. The Microsoft Ajax Minifier (download here) includes a msbuild task, making the effort of creating minified scripts painless.
I followed these basic instructions for adding the build task:
So, based on this documentation (MSBuild Items), I changed the basic Include settings to reflect my folder structure.
<Import Project="$(MSBuildExtensionsPath)\Microsoft\MicrosoftAjax\ajaxmin.tasks" /> <Target Name="AfterBuild"> <ItemGroup> <JS Include="Scripts\Views\\**\*.js" Exclude="Scripts\Views\\**\*.min.js;" /> </ItemGroup> <ItemGroup> <CSS Include="**\*.css" Exclude="**\*.min.css" /> </ItemGroup> <AjaxMin JsSourceFiles="@(JS)" JsSourceExtensionPattern="\.js$" JsTargetExtension=".min.js" CssSourceFiles="@(CSS)" CssSourceExtensionPattern="\.css$" CssTargetExtension=".min.css" /> </Target>
Roughly translated to English, the above:
- Skip anything that is already named *.min.js