In this recipe, we will learn how to bundle and minify two JavaScript files with the Gulp task runner.
We will assume that you've already installed Visual Studio 2015 Community Edition, and that the installer automatically installed Node.js and npm. Here are the two JavaScript files to bundle and minify:
Let's see the code of the first of these two files:
Here is the code of the second:
- First, we add Gulp to
package.json
and theGulp
plugins. Then we need to minify and bundle these two JavaScript files if this file doesn't exist in the web application:
- We add the
gulp-concat
plugin, which concatenates the (bundle) files, and then we addgulp-uglify
, which minifies the.js
files, removing whitespaces and comments, and writes the name of the module we want to add to thedevDependencies
section:
- Let's create a
gulpfile.js
(a gulp configuration file):
- The generated file contains the following code:
- Let's add the following...