AjaxMin Build Task to minify all js to separate folder

十年热恋 提交于 2019-12-12 01:08:47

问题


I m using ajaxmin to minify all my JS files. Everything works perfectly but i have little problem with the way the output files are generated.

Currently what happenes is the JS files are minified next to its path. e.g If the original path is includes/js/test.js then it is minified at includes/js/test.min.js.

I want my all js files to minify at different location then the original location. e.g. My all js files are under includes/js/JSFILESHERE and i wanted these js files to be minified at includes/minifiedjs/MINIFIEDJSFILESHERE.

i m using the below code.

    <Import Project="$(MSBuildExtensionsPath)\Microsoft\MicrosoftAjax\AjaxMin.tasks" />
    <Target Name="AfterBuild">
        <ItemGroup>
            <JS Include="\js\*.js" Exclude="**\*.min.js;" />
        </ItemGroup>  
    <AjaxMin JsSourceFiles="@(JS)" JsSourceExtensionPattern="\js\.js$" JsTargetExtension=".min.js"/>
    </Target>

Please help.


回答1:


Apologies for replying bit late to this question.

Here is the solution I used for my project -

<Target Name="AfterBuild">
<PropertyGroup>
  <DestinationPath>$(MSBuildProjectDirectory)\build-publish</DestinationPath>
</PropertyGroup>
<ItemGroup>
  <JS Include="Scripts\app\**\*.js" Exclude="**\*.min.js;Scripts\*.js" />
</ItemGroup>
<Copy SourceFiles="@(JS)" DestinationFiles="@(JS -> '$(DestinationPath)\%(RecursiveDir)%(Filename).src%(Extension)')" Condition="'%(Extension)'=='.js'">
  <Output ItemName="JavaScriptFiles" TaskParameter="DestinationFiles" />
</Copy>
<AjaxMin JsSourceFiles="@(JavaScriptFiles)" JsSourceExtensionPattern="\.src.js$" JsTargetExtension="min.js" SourceMapType="V3">
</AjaxMin>

Here am first copying the files to a destination folder(recursively) and then applying the Minification on them. I needed source map files so thats why I kept my original files but if you dont need source maps then you could delete source files after minification is complete.



来源:https://stackoverflow.com/questions/17146832/ajaxmin-build-task-to-minify-all-js-to-separate-folder

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!