Originally posted on http://geekswithblogs.net/Aligned/archive/2014/08/19/run-grunt-task-in-visual-studio-release-build-with-a.aspx
- Add a
BeforeBuild
in your csproj file. Edit the XML with a text editor.
<Target Name="BeforeBuild">
<Exec Condition="'$(Configuration)' == 'Release'" Command="script-optimize.bat" />
</Target>
- Create the script-optimize.bat:
REM "%~dp0" maps to the directory where this file exists
cd %~dp0\..\YourProjectFolder
call npm uninstall grunt
call npm uninstall grunt
call npm install --cache-min 604800 -g grunt-cli
call npm install --cache-min 604800
grunt typescript requirejs copy less:compile less:mincompile
This grunt command will compile typescript, run the requireJs optimizer, compile and minimize less.
- Make it use the minified code when the Web.config compilation debug is set to
false
.
<Target Name="CustomCollectFiles">
<ItemGroup>
<_CustomFiles Include="Scripts-Release\**\*" />
</ItemGroup>
</Target>
That should be all you need to get a Grunt task to minify and combine JS (plus other tasks) in Visual Studio Release build with debug = false
.
This is a great video of Steve Sanderson talking about SPAs, npm, Knockout, Grunt, Gulp, etc. I highly recommend it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.