Java Reference
In-Depth Information
This file contains two tasks: the js task and the default task. The js task will use the
stripdebug plugin to remove the debugging console.log commands, and then use
the uglify plugin to minify the code. Run this task using this terminal command:
$ gulp js
After running the task, you should find a file called scripts.js inside the js folder. The con-
tents of this file should contain the minified code and be smaller in size than the original
file.
There is also the default task. This runs our js task and then watches for any file up-
dates. If a file is added, removed, or modified in the src folder, the js task is run again.
Run the default task using the following command:
$ gulp
More plugins and tasks can be added to gulpfile.js. For example, if our project JavaScript
was contained in several separate, smaller files, we could use a Gulp task to concatenate to-
gether, or we could add a CSS preprocessor such as Sass to compile SCSS to normal CSS.
You can even write a Gulp task that would watch for changes to the files, and run a JS Lint
test on it whenever these changes signalled any mistakes made in the code.
Although we haven't changed the functionality of the quiz game in this chapter, we have
made it more modular and therefore easier to maintain in the future, as well as optimizing
the file size, ready for deployment. These are both important tasks to consider when writ-
ing JavaScript that will be deployed to a server.
Search WWH ::




Custom Search