简体   繁体   English

仅在发布后而非构建时使用NPM最小化javascript

[英]Minimize javascript using NPM on Post Publish only and not on Build

I am trying to minify JS files using NPM commands. 我正在尝试使用NPM命令缩小JS文件。 I need minify command must run only on Post Publish and not on Build. 我需要minify命令必须仅在发布后才能运行,而不能在Build上运行。 But currently it runs after build and publish both. 但是目前它在构建和发布后都运行。 I have written the following code in Package.json: 我在Package.json中编写了以下代码:

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

I have created a new DefaultTarget in .csproj 我在.csproj中创建了一个新的DefaultTarget

<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. 在构建和发布两者之后,它将最小化JS文件。 Where as I need to restrict it to Publish only. 我需要将其限制为仅发布。

Please let me know if I am missing something. 如果我缺少什么,请告诉我。

Remove "AfterPublish" from the project DefaultTargets and try the following change to the AfterTargets property: 从项目DefaultTargets中删除“ AfterPublish”,然后尝试对AfterTargets属性进行以下更改:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM