0

I am trying to minify JS files using NPM commands. I need minify command must run only on Post Publish and not on Build. But currently it runs after build and publish both. I have written the following code in Package.json:

"scripts": {
    "uglify": "recursive-uglifyjs ./Scripts/src/"
}

I have created a new DefaultTarget in .csproj

<Project ToolsVersion="12.0" DefaultTargets="Build;AfterPublish" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

And code for target is:

 <Target Name="AfterPublish" AfterTargets="MSDeployPublish">
<Exec Command="npm run uglify " />
<Exec Command="echo $(Configuration)"></Exec>
<Exec Command="echo testing..after publiosh " />

Whenever I run this. It minify JS files after build and publish both. Where as I need to restrict it to Publish only.

Please let me know if I am missing something.

Gagan Bajaj
  • 169
  • 1
  • 16

1 Answers1

0

Remove "AfterPublish" from the project DefaultTargets and try the following change to the AfterTargets property:

<Target Name="AfterPublish" AfterTargets="GatherAllFilesToPublish">
<Exec Command="npm run uglify " />
<Exec Command="echo $(Configuration)"></Exec>
<Exec Command="echo testing..after publiosh " />
Alan Donnelly
  • 79
  • 1
  • 3
  • Thanks Alan, the issue is resolved. I have further used following reference to resolve it: http://stackoverflow.com/questions/28409352/pubxml-web-publish-tool-event-lifecycle – Gagan Bajaj Jun 23 '16 at 14:04