Use Gulp in ASP.NET Core

In a typical modern web app, the build process might.

  • Bundle and minify JavaScript and CSS files.
  • Run tools to call the bundling and minification tasks before each build.
  • Compile LESS or SASS files to CSS.
  • Compile CoffeeScript or TypeScript files to JavaScript.

A task runner is a tool which automates these routine development tasks and more. Visual Studio provides built-in support for two popular JavaScript-based task runners: Gulp and Grunt.

Gulp

Gulp is a JavaScript-based streaming build toolkit for client-side code. It's commonly used to stream client-side files through a series of processes when a specific event is triggered in a build environment. For instance, Gulp can be used to automate bundling and minification or the cleansing of a development environment before a new build.

A set of Gulp tasks is defined in gulpfile.js. The following JavaScript includes Gulp modules and specifies file paths to be referenced within the forthcoming tasks:

  1. /// <binding Clean='clean' />  
  2. "use strict";  
  3.   
  4. var gulp = require("gulp"),  
  5.   rimraf = require("rimraf"),  
  6.   concat = require("gulp-concat"),  
  7.   cssmin = require("gulp-cssmin"),  
  8.   uglify = require("gulp-uglify");  
  9.   
  10. var paths = {  
  11.   webroot: "./wwwroot/"  
  12. };  
  13.   
  14. paths.js = paths.webroot + "js/**/*.js";  
  15. paths.minJs = paths.webroot + "js/**/*.min.js";  
  16. paths.css = paths.webroot + "css/**/*.css";  
  17. paths.minCss = paths.webroot + "css/**/*.min.css";  
  18. paths.concatJsDest = paths.webroot + "js/site.min.js";  
  19. paths.concatCssDest = paths.webroot + "css/site.min.css"
The above code specifies which Node modules are required. The require function imports each module so that the dependent tasks can utilize their features. Each of the imported modules is assigned to a variable. The modules can be located either by name or path. In this example, the modules named gulp, rimraf, gulp-concat, gulp-cssmin, and gulp-uglify are retrieved by name. Additionally, a series of paths are created so that the locations of CSS and JavaScript files can be reused and referenced within the tasks.
 
Click here for full description.