Gulp is a task-runner and automation tool to help you build a web app or website. You can use Gulp modules to programmatically execute all sorts of tedious tasks that take too much time when typed by hand. Gulp is Javascript based and integrates with just about everything – from CSS to Javascript, HTML, PHP, the file system, images, etc. It’s extremely helpful to speed up the time it takes to produce a website, as well as for bullet-proofing more of the final product. The following is a list of 8 time saving website development tasks you can automate using Gulp.
Moving Source Files to Production
You can use Gulp tasks to move files from a source directory to a public (or “buildâ€) directory automatically. Often, files in the source (or “developmentâ€) directory are verbose and uncompressed and files in the build directory are compressed and optimized for public service. Piping commands to Gulp’s src and dest functions is out-of-the-box service.
Compiling Sass Files to CSS
You can use Gulp tasks to compile Sass files into optimized CSS. Stylesheets for websites need to be CSS for web browsers to interpret the code and correctly display your website’s design. Using a gulp compiler module translates your Sass code into CSS and lets you choose whether or not to minify the output. Gulp-sass
, gulp-sass-globbing
, and node-sass
are great modules for compiling Sass files to CSS using Gulp task automation.
Concatenating Files and Scripts
You can use Gulp to concatenate multiple files – like Javascript files or cascading stylesheets – into a single script. Minimizing the amount of scripts you need to load on any given pages reduces the number of requests your making to the web server and helps optimize page-load-times and time-to-first-load – it’s a better user-experience for website visitors. Gulp-concat
is a module to checkout for doing file concatenation with Gulp.
File Minification
You can use Gulp for file minification. Removing all the unnecessary spaces helps reduce the overall footprint of the code within a file, so the file will load faster. Websites with faster loading times rank better in Google Search Results Pages and provide better user-experiences for people visiting your website who enjoy instant exchanging of information. Minification is typically a feature of other plugins – for example, gulp-sass
has an option to compress your output – but there are dedicated minification modules like cssnano
, too.
File Uglification
You can use Gulp to uglify your CSS and Javascript files. Uglification is the transformation of code into an unreadable form – changing the names of variables, functions, etc. – to mask the original content. It’s common practice on most professionally built websites to obscure code, as a way of protecting any competitive advantage from programmatic efficiencies within. Uglification also adds a layer of minification from the simplification and programmatic changing of the code, so similarly to file minification you’ll gain another incremental amount of speed. Two modules for uglifying JS and CSS files are gulp-uglify
and gulp-uglifyCss
.
Auto Prefixing CSS
You can use Gulp to auto-prefix your CSS for broader browser compatibility. Instead of spending lots of unnecessary time hand-coding browser-prefixes to your CSS stylesheet declarations you can write styles in the most general common basic way and a Gulp task can take care of programmatically adding browser prefixes to support browsers you need to support wherever the prexes are needed – no guessing. This trick isn’t a speed booster, but it will help keep your website from looking broken in way more browsers than if you don’t use it (probably). Gulp-autoprefixer
is a Gulp module that does what it sounds like.
Launching a Development Server with Live Refresh
You can use Gulp to launch a web server from your local development folder, watch files for changes, and live-refresh the web browser to preview the updates. Modules like browsersync
let you do exactly that (and more). Automation tasks like starting a web server, monitoring for file changes so scripts know when to compile, and reloading the browser (i.e. syncing the browser) is a huge time saver. It saves you from moving your hands to use the mouse, clicking, changing windows, turning your head to look at a different monitor, and probably even more little things you might not notice until you add up all the time you saved from not doing them. Time savers are time saviors.
Optimizing Images and SVG Files
You can use Gulp to optimize image and SVG files. Just like file minification, graphic files can be optimized for reduces file size and faster load times, too. Running a simple Gulp module like gulp-imagemin
can significantly reduce the size of the resources you’re web pages are loading and that’s super cool. It’s slightly more involved to setup initially, but running a Gulp task is akin to pressing a button – a magic button.
0 Comments