I\'ve set up an ASP.NET 5 project in Visual Studio and created a gulpfile.js which I use to build my typescript and less files.
For release builds, I want to uglify
When you're using Visual Studio and your project template is a Blank App (Apache Cordova) and you cannot see any Build Events when you right-click on ProjectName in Solution Explorer and go to Properties like below:
You can then manage your Solution Configuration using Cordova hooks. These are the special scripts injected in your solution to customize cordova commands and are executed with your solution activities/events. For more information, see this.
Steps to follow:
In the root directory of your project, create a new folder (say, 'hooks') containing the hook javascript file (say 'solutionConfigHook.js') as follows:
"use strict";
// function to run the '_default' task in 'gulpfile.js'
// based on solution configuration (DEBUG or RELEASE) prior to building the solution
module.exports = function (context) {
var config = getConfig(context.cmdLine);
if (!config) {
console.log('Unable to determine build environment!');
return;
}
else {
var exec = require('child_process').exec, child;
console.log('Runnung Gulp tasks now...');
// 'solutionConfig' is the command line argument for config value passed to the gulpfile
// '_default' is the task name in *gulpfile.js* that will have access to 'solutionConfig'
var gulpCommand = 'gulp _default --solutionConfig ' + config.toString();
console.log(gulpCommand);
child = exec(gulpCommand, function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
}
}
// function to get the solution configuration using CLI
function getConfig(cmdLine) {
var matches = /--configuration (\w+)/.exec(cmdLine);
if (matches && matches.length > 1) {
return matches[1];
}
return null;
}
Add this hook in your config.xml file as follows for each platform against the desired hook type.
(For your reference, the code snipped here is for windows platform alone and is called for 'before_build' hook type.)
... // other resources or attributes
In your gulpfile.js, remove the binding of the task(s) by either deleting the reference on top or by going to the Task Runner Explorer and then right-clicking each task and unchecking all bindings.
Add a task in your gulpfile.js that will be called by the hook itself on the activity defined as hook type in config.xml.
gulp.task('_default', function (solutionConfig) {
if (solutionConfig == "Release") {
// perform desired task here
}
else if (solutionConfig == "Debug" {
// perform desired task here
}
});