{"id":9,"date":"2019-08-09T13:15:00","date_gmt":"2019-08-09T13:15:00","guid":{"rendered":"https:\/\/dev.kloclabs.com\/?p=9"},"modified":"2023-11-10T11:02:10","modified_gmt":"2023-11-10T11:02:10","slug":"16-awesome-gulp-plugins","status":"publish","type":"post","link":"https:\/\/kloclabs.com\/16-awesome-gulp-plugins\/","title":{"rendered":"16 awesome gulp plugins which will improve your workflow"},"content":{"rendered":"\n

I used to be the kind of person who would just write some code, then shove it on a web server. I now know the error of my ways, a build process can really help either reduce your workload (If you’re already doing the things manually) or even better automate things you didnt even think (or know) you needed.<\/p>\n

To achieve this, I usually use Gulp<\/a>. This tool lets you string a build process together. So let me give you an example: You want to minify all files, create source maps of your CSS and JS, create new version numbers for your assets, compress images, create your favicons etc. All this and much more can be done in a single command.<\/p>\n

So I thought I would talk about a few of the Gulp plugins I use for my build process. I’ll split them down by styles, scripts, html etc.<\/p>\n

Styles<\/h2>\n

gulp-sass<\/a><\/h3>\n

This plugin compiles your SASS into a CSS file. (If you couldn’t guess from it’s name). This is super useful, as you can write your styles in sass and this will compile it into CSS. This can be either on the fly with browsersync (we’ll talk about this later) or when you build the final project.<\/p>\n

gulp-cssnano<\/a><\/h3>\n

This plugin lets you minify your CSS within your build process. Minification enables a file to be smaller by removing whitespace and linebreaks, update variable names to be shorter, removing comments and changing some functions be less readable. (Such as changing the boolean false to !1).<\/p>\n

critical<\/a><\/h3>\n

This generates your critical CSS from your CSS and adds it to the <head> section. If you want some tips on how to improve your page speed. I have talked about this on a previous blog post<\/a>. <\/p>\n

autoprefixer<\/a><\/h3>\n

This plugin is one of my favourites. It adds browser specific prefixes so you don’t have to. So for instance using the CSS ‘border-radius’, you may also want to include ‘-webkit-border-radius’, your gulp build process will add this for you.<\/p>\n

Scripts<\/h2>\n

gulp-uglify<\/a><\/h3>\n

This is very similar to gulp-cssnano but it is used for JS. It minifies your scripts to help speed up your PLS, and speeds up execution times. <\/p>\n

gulp-eslint<\/a><\/h3>\n

This plugin tests your JS, it looks for any errors, looks for any unused variables or arguments. It can also fix any issues if you want it to. There are also various ESLint plugins which can detect problems with libraries too. The example below is an AngularJS app. <\/p>\n\n\n\n\n

\"An
An example of ESLint output<\/figcaption><\/figure>\n\n\n\n

HTML<\/h2>\n

gulp-useref<\/a><\/h3>\n

This plugin concatenates any scripts or stylehseets. This helps if you’re using HTTP\/1.1 as it’s quicker to download 1 file rather than several. As we move to HTTP\/2 this becomes less relevant.<\/p>\n

gulp-htmlmin<\/a><\/h3>\n

Similar to gulp-cssnano or gulp-uglify this minifies yout HTML. (If you couldn’t guess already) There are various options you can use on this too which can make it more agressive. Such as removing quote marks where they’re not needed. <\/p>\n\n\n\n

\"Before
Before running gulp-htmlmin<\/figcaption><\/figure>\n\n\n\n
\"\"
After running gulp-htmlmin<\/figcaption><\/figure>\n\n\n\n

As you can see, it has removed line breaks and spaces and quotes around any single word attributes in this small file.<\/p>\n

Images<\/h2>\n

gulp-imagemin<\/a><\/h3>\n

This plugin minifies any images used in the project. This is usually through the means of removing some quality from JPEG’s, removing any unused lines of code from SVG’s etc. This can help reduce the size of all the images used without the tedius task of doing it manually.<\/p>\n

Other<\/h2>\n

browsersync<\/a><\/h3>\n

Browersync lets you preview your site, it’s great for working on in development as it taylors it for you. Here are a few of the benefits when using browsersync in development:<\/p>\n

When you save files, it will reload your siteKeep 2 browsers in sync with one another (I find this is especially beneficial when working on a desktop and mobile site). This works for both interactions, scrolling and navigation.Check your site in different network conditions<\/p>\n

gulp-load-plugins<\/a><\/h3>\n

This ones a realy simple one, it lets you pull in any plugins with the prefix gulp into your Gulpfile so you don’t have to have them all included. You can then use the plugins through the use of an object or your choice. <\/p>\n

gulp-rev<\/a><\/h3>\n

This plugin adds hashes to the end of file names of static assets. This is useful, especially if you want to be agressive with your caching on your server. You can set an expiry date far into the future for your CSS and JS. Then if any changes are made, they will have a different file name which, in turn will have a long cache. This will make your website or application faster because your users are able to cache major assets. As an example app.js <\/strong>may change to app-2f6e8c0f32.js<\/strong>. If saved as app.js, this may cause problems with users caching the JS and running out of date JS.<\/p>\n

gulp-cdnizer<\/a><\/h3>\n

I find this plugin useful as I try to use CDN’s where possible for any libraries used. It lets you replace any local libraries with the CDN equivalent. So I would use this for libraries such as AngularJS. I would have a local version to work in when developing which would be unminified. When building for production I would run that library through gulp-cdnizer and change it to a minified version on CDNJS<\/a> in production. <\/p>\n

gulp-replace<\/a><\/h3>\n

gulp-replace is a very simple plugin that takes a string and replaces it with another. I use this for replacing a comment in the HTML to Critical CSS. Most projects may not need it, but it’s a useful one to know about if you need it!<\/p>\n

gulp-flatten<\/a><\/h3>\n

gulp-flatten helps you generate the tree you want for your files. This is especially useful if you’re wanting certain types files to be in the same place. One use would be structuring your bower components. Rather than having the default tree which may look something like this:<\/p>\n\n\n\n

\"Before
Before using gulp-flatten<\/figcaption><\/figure>\n\n\n\n
\"After
After using gulp-flatten<\/figcaption><\/figure>\n\n\n\n

This makes it easy to have your files in a repeatable place rather than having them in whatever folder they are in by default.<\/p>\n

gulp-sourcemaps<\/a><\/h3>\n

This plugin lets you generate source maps for your CSS and JS. Source maps enable you to debug your site in production by providing a way to show how the file would look, without minifcation and combination. This gulp plugin will generate them, then reference them in the relevant files. <\/p>\n

Conclusion<\/h2>\n

There are many other plugins too. Depending on your workflow, you may want to remove or add some plugins. There’s a plugin for practically any task you may want to automate. There’s some for generating fav icons for example.<\/p>\n

Gulp is amazing at dealing with the little jobs so you don’t have to. The plugins above help improve your workflow and be run in many different ways. I usually have a build process for a final build, another for development using browsersync etc. and one for testing.<\/p>\n","protected":false},"excerpt":{"rendered":"

A better web workflow can help you save time and effort in many aspects of your build. A lot of tasks normally performed during or after your build can be automated!<\/p>\n","protected":false},"author":1,"featured_media":22,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"yoast_head":"\n16 awesome gulp plugins which will improve your workflow - Kloc Labs<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/aaron-russell.co.uk\/blog\/16-awesome-gulp-plugins\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"16 awesome gulp plugins which will improve your workflow - Kloc Labs\" \/>\n<meta property=\"og:description\" content=\"A better web workflow can help you save time and effort in many aspects of your build. A lot of tasks normally performed during or after your build can be automated!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/aaron-russell.co.uk\/blog\/16-awesome-gulp-plugins\/\" \/>\n<meta property=\"og:site_name\" content=\"Kloc Labs\" \/>\n<meta property=\"article:published_time\" content=\"2019-08-09T13:15:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-11-10T11:02:10+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/kloclabs.com\/wp-content\/uploads\/2022\/08\/photo-1521913728990-c534455c5454.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1080\" \/>\n\t<meta property=\"og:image:height\" content=\"743\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"aaron\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"aaron\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/kloclabs.com\/16-awesome-gulp-plugins\/\",\"url\":\"https:\/\/aaron-russell.co.uk\/blog\/16-awesome-gulp-plugins\/\",\"name\":\"16 awesome gulp plugins which will improve your workflow - Kloc Labs\",\"isPartOf\":{\"@id\":\"https:\/\/kloclabs.com\/#website\"},\"datePublished\":\"2019-08-09T13:15:00+00:00\",\"dateModified\":\"2023-11-10T11:02:10+00:00\",\"author\":{\"@id\":\"https:\/\/kloclabs.com\/#\/schema\/person\/2e6cd7fffdd77875c71a48cd38d9b5a8\"},\"breadcrumb\":{\"@id\":\"https:\/\/aaron-russell.co.uk\/blog\/16-awesome-gulp-plugins\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/aaron-russell.co.uk\/blog\/16-awesome-gulp-plugins\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/aaron-russell.co.uk\/blog\/16-awesome-gulp-plugins\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/kloclabs.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"16 awesome gulp plugins which will improve your workflow\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/kloclabs.com\/#website\",\"url\":\"https:\/\/kloclabs.com\/\",\"name\":\"Kloc Labs\",\"description\":\"Web and App Development, Hosting and more!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/kloclabs.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/kloclabs.com\/#\/schema\/person\/2e6cd7fffdd77875c71a48cd38d9b5a8\",\"name\":\"aaron\",\"sameAs\":[\"http:\/\/kloclabs.com\"],\"url\":\"https:\/\/kloclabs.com\/author\/aaron\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"16 awesome gulp plugins which will improve your workflow - Kloc Labs","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/aaron-russell.co.uk\/blog\/16-awesome-gulp-plugins\/","og_locale":"en_US","og_type":"article","og_title":"16 awesome gulp plugins which will improve your workflow - Kloc Labs","og_description":"A better web workflow can help you save time and effort in many aspects of your build. A lot of tasks normally performed during or after your build can be automated!","og_url":"https:\/\/aaron-russell.co.uk\/blog\/16-awesome-gulp-plugins\/","og_site_name":"Kloc Labs","article_published_time":"2019-08-09T13:15:00+00:00","article_modified_time":"2023-11-10T11:02:10+00:00","og_image":[{"width":1080,"height":743,"url":"https:\/\/kloclabs.com\/wp-content\/uploads\/2022\/08\/photo-1521913728990-c534455c5454.jpg","type":"image\/jpeg"}],"author":"aaron","twitter_card":"summary_large_image","twitter_misc":{"Written by":"aaron","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/kloclabs.com\/16-awesome-gulp-plugins\/","url":"https:\/\/aaron-russell.co.uk\/blog\/16-awesome-gulp-plugins\/","name":"16 awesome gulp plugins which will improve your workflow - Kloc Labs","isPartOf":{"@id":"https:\/\/kloclabs.com\/#website"},"datePublished":"2019-08-09T13:15:00+00:00","dateModified":"2023-11-10T11:02:10+00:00","author":{"@id":"https:\/\/kloclabs.com\/#\/schema\/person\/2e6cd7fffdd77875c71a48cd38d9b5a8"},"breadcrumb":{"@id":"https:\/\/aaron-russell.co.uk\/blog\/16-awesome-gulp-plugins\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/aaron-russell.co.uk\/blog\/16-awesome-gulp-plugins\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/aaron-russell.co.uk\/blog\/16-awesome-gulp-plugins\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/kloclabs.com\/"},{"@type":"ListItem","position":2,"name":"16 awesome gulp plugins which will improve your workflow"}]},{"@type":"WebSite","@id":"https:\/\/kloclabs.com\/#website","url":"https:\/\/kloclabs.com\/","name":"Kloc Labs","description":"Web and App Development, Hosting and more!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/kloclabs.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/kloclabs.com\/#\/schema\/person\/2e6cd7fffdd77875c71a48cd38d9b5a8","name":"aaron","sameAs":["http:\/\/kloclabs.com"],"url":"https:\/\/kloclabs.com\/author\/aaron\/"}]}},"_links":{"self":[{"href":"https:\/\/kloclabs.com\/wp-json\/wp\/v2\/posts\/9"}],"collection":[{"href":"https:\/\/kloclabs.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kloclabs.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kloclabs.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kloclabs.com\/wp-json\/wp\/v2\/comments?post=9"}],"version-history":[{"count":2,"href":"https:\/\/kloclabs.com\/wp-json\/wp\/v2\/posts\/9\/revisions"}],"predecessor-version":[{"id":31,"href":"https:\/\/kloclabs.com\/wp-json\/wp\/v2\/posts\/9\/revisions\/31"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kloclabs.com\/wp-json\/wp\/v2\/media\/22"}],"wp:attachment":[{"href":"https:\/\/kloclabs.com\/wp-json\/wp\/v2\/media?parent=9"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kloclabs.com\/wp-json\/wp\/v2\/categories?post=9"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kloclabs.com\/wp-json\/wp\/v2\/tags?post=9"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}