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
Here is another solution that allows you to pass the configuration as a flag to your gulp task, instead of running the configuration as the task itself. This would allow you to use gulp-if to trigger different procedures from within the task.
Note: This answer assumes that gulp isn't installed globally.
Install gulp as a dev dependency
npm install gulp --save-dev
Register gulp as an npm script
{
"name": "vs-build-test",
...
"scripts": {
"gulp": "gulp"
}
}
Install yargs to handle custom flags
npm install yargs --save-dev
Require yargs in gulpfiles.js
with a default for the configuration
flag
var argv = require('yargs').default('configuration', 'Debug').argv
Create a build task in gulpfile.js
gulp.task('build', function () {
console.log(`Build Configuration: ${argv.configuration}`);
});
Add a pre-build event to run gulp [Project Properties -> Build Events -> Pre-build Event]
cmd.exe /c npm run gulp build -- --configuration $(ConfigurationName)
The reason this can be useful is so that you can use the same tasks but conditionally run only portions of the process. Take for example a task that builds javascript:
gulp.task('build:js', function () {
let isProduction = ${argv.configuration} === 'Release';
...
return gulp.src(source)
.pipe(gulpif(!isProduction, sourcemaps.init()))
.pipe(concat(outputFile, { newLine: ';' }))
.pipe(gulpif(isProduction, closure(closureFlags)))
.pipe(gulpif(!isProduction, sourcemaps.write()))
.pipe(gulp.dest(basePath));
});