{"id":819,"date":"2016-01-11T07:24:05","date_gmt":"2016-01-10T22:24:05","guid":{"rendered":"http:\/\/n8finch.com\/?p=819"},"modified":"2016-08-25T11:03:28","modified_gmt":"2016-08-25T02:03:28","slug":"learning-new-things-grunt","status":"publish","type":"post","link":"https:\/\/n8finch2024.local\/learning-new-things-grunt\/","title":{"rendered":"Learning New Things: Grunt"},"content":{"rendered":"

I’m still getting a handle on Grunt. As far as a build tool, I’ve not yet been able to wrap my head completely around it.<\/p>\n

Maybe I need a better tutorial, or maybe I just need to not get hung up on any task runner that isn’t working right (looking at you, livereload<\/em><\/strong>!).<\/p>\n

I’ll get it figured out. I usually do:-).<\/p>\n

Until then, I wanted to make some notes about what I’d see so far, and what I’ve done. I had some help from the Grunt documentation<\/a><\/strong>, as well as some good tutorials<\/a><\/strong>. This isn’t a tutorial, just some notes. If you’re looking for how-tos, follow\u00a0the links…<\/p>\n

Installing Grunt and Extras<\/h2>\n

So,\u00a0for anyone who’s new, you’ll want to install Grunt globally and on a per-project basis. The global install gets you the Grunt command line interface (cli) (which is npm install -g grunt-cli<\/code>), and then grunt installation per project allows you to run the tasks you (or someone else!) has set up. Pretty sweet that someone can compile a whole set of tasks for you to run, and all you have to do is npm install<\/code> and then run grunt<\/code>.<\/p>\n

Nice.<\/p>\n

Installing Grunt Plugins<\/h2>\n

Like WordPress plugins, it’s easy to get a little trigger happy with plugins. They let you do extra tasks you couldn’t before and it’s just a command away.<\/p>\n

Whenever installing Grunt plugins to the project, you want to make sure to post fix --save-dev<\/code> to the end of the install command. This will keep all of the plugins listed in the dev dependencies section of your package.json file.<\/p>\n

Here are some plugins I’ve installed and have been trying to get to work (with more success than not):<\/p>\n

npm install grunt-contrib-sass --save-dev \/\/installs Sass compiler\r\nnpm install grunt-contrib-watch --save-dev \/\/installs the watch which, yes, watches for changes in specified files.\r\nnpm install grunt-autoprefixer --save-dev \/\/install the autoprefixers for different browsers so you don't have to worry about prefixing in CSS \r\nnpm install grunt-reload \/\/installs the live reload, or at least is supposed to... \r\nnpm install grunt-contrib-connect --save-dev \/\/install the companion for live reload, which I can't get to work... yet! \r\nnpm install grunt-contrib-concat --save-dev \/\/install the ability to concatenate files, like javascript and CSS files, into one massive file.<\/pre>\n

These are just a few of the thousands of plugins<\/a><\/strong> available for Grunt.<\/p>\n

Configuring All the Tasks<\/h2>\n

This is where the waters start to get a little murky for me. That’s ok, for now. I’ve mostly been copying, pasting, editing and testing the provided scripts (see this one<\/a><\/strong> for an example). I basically look at how the example is using the code, try to understand it, copy it in, and customize it to work for what I’m trying to do.<\/p>\n

Nice way to hack at Grunt, right?<\/p>\n

Maybe.<\/p>\n

Currently, I’m not able to do all of the tasks I’ve installed, and I’m not sure why. The two big things are:<\/p>\n

    \n
  1. Compiling Bootstrap\u00a0Sass in CSS<\/li>\n
  2. Running the livereload task<\/li>\n<\/ol>\n

    I literally have spent two hours tweaking things with no idea why things won’t compile or live reload. They’re not huge deals. I can always just copy the most recent bootstrap.css file and enqueue it, but the point is to use Grunt (and Bower).<\/p>\n

    And live reload isn’t\u00a0necessary<\/em><\/strong>, but it would just be nice.<\/p>\n

    Here’s what I’ve got so far in my Gruntfile.js<\/code>. It runs with no errors, but doesn’t do everything I want it to (yet!):<\/p>\n

    module.exports = function(grunt) {\r\n\r\n    grunt.initConfig({\r\n\t\tpkg: grunt.file.readJSON('package.json'),\r\n\r\n\t\t\/**\r\n\t\t * Sass\r\n\t\t *\/\r\n\t\tsass: {\r\n\t\t  dev: {\r\n\t\t    options: {\r\n\t\t      style: 'expanded',\r\n\t\t      sourcemap: 'none',\r\n\t\t    },\r\n\t\t    files: {\r\n\t\t      'style-human-readable.css': 'sass\/style.scss',\r\n\/\/\t\t\t\t\t'bootsasscompiled.css': '**\/vendor\/boostrap-sass\/assets\/stylesheets\/_bootstrap.scss'\r\n\t\t    }\r\n\t\t  },\r\n\t\t  dist: {\r\n\t\t    options: {\r\n\t\t      style: 'compressed',\r\n\t\t      sourcemap: 'none',\r\n\t\t    },\r\n\t\t    files: {\r\n\t\t      'style.css': 'sass\/style.scss'\r\n\t\t    }\r\n\t\t  }\r\n\t\t},\r\n\t\t\r\n\t\t\r\n\t\tconcat : {\r\n\t\t      options: {\r\n\t\t        separator: '\\n\\n\/\/------------------------------------------\\n',\r\n\t\t        banner: '\\n\\n\/\/------------------------------------------\\n'\r\n\t\t      },\r\n\t\t      dist : {\r\n\t\t        src: ['js\/*.js'],\r\n\t\t        dest: 'concatjs.js'\r\n\t\t      },\r\n\t\t\t\t\tdev: {\r\n\t\t\t\t\t\tsrc: [],\r\n\t\t\t\t\t\tdest: 'bootconcat.css'\r\n\t\t\t\t\t}\r\n\t\t    }, \/\/concat\r\n\t\t\r\n\t  \/**\r\n\t   * autoprefixer\r\n\t   *\/\t\r\n\t\tautoprefixer: {\r\n\t\t\toptions: {\r\n\t\t\t\tbrowsers: ['last 2 versions']\r\n\t\t\t},\r\n\t\t\tmultiple_files: {\r\n\t\t\t\texpand: true,\r\n\t\t\t\tflatten: true,\r\n\t\t\t\tsrc: 'compiled\/*.css',\r\n\t\t\t\tdest: ''\r\n\t\t\t}\r\n\t\t},\r\n\r\n\t  \/**\r\n\t   * Watch\r\n\t   *\/\r\n\t\twatch: {\r\n\t    options: {\r\n\t      livereload: true,\r\n\t    },\r\n\t\t\tcss: {\r\n\t\t\t\tfiles: '**\/*.scss',\r\n\t\t\t\ttasks: ['sass','autoprefixer']\r\n\t\t\t}\r\n\t\t},\r\n\r\n\t});\r\n\tgrunt.loadNpmTasks('grunt-contrib-sass');\r\n\tgrunt.loadNpmTasks('grunt-contrib-concat');\r\n\tgrunt.loadNpmTasks('grunt-contrib-watch');\r\n\tgrunt.loadNpmTasks('grunt-autoprefixer');\r\n\tgrunt.registerTask('default',['concat', 'sass', 'watch']);\r\n}<\/pre>\n

    Conclusion<\/h2>\n

    I’m excited about Grunt, because it opens me up to using Sass (or LESS), compiling it all to CSS, keeping my production files to a minimum (and minified!), and allows me to use the tools\u00a0real developers<\/em><\/strong> use.<\/p>\n

    Now, I’ve just gotta fix some tasks…<\/p>\n

    Peace,<\/p>\n

    Nate<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"

    I’m still getting a handle on Grunt. As far as a build tool, I’ve not yet been able to wrap my head completely around it. Maybe I need a better tutorial, or maybe I just need to not get hung up on any task runner that isn’t working right (looking at you, livereload!). I’ll get […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_eb_attr":"","footnotes":""},"categories":[9,1,8],"tags":[],"yoast_head":"\nLearning New Things: Grunt | Nate Finch<\/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:\/\/n8finch-site.site.strattic.io\/learning-new-things-grunt\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Learning New Things: Grunt | Nate Finch\" \/>\n<meta property=\"og:description\" content=\"I’m still getting a handle on Grunt. As far as a build tool, I’ve not yet been able to wrap my head completely around it. Maybe I need a better tutorial, or maybe I just need to not get hung up on any task runner that isn’t working right (looking at you, livereload!). I’ll get […]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/n8finch-site.site.strattic.io\/learning-new-things-grunt\/\" \/>\n<meta property=\"og:site_name\" content=\"Nate Finch\" \/>\n<meta property=\"article:published_time\" content=\"2016-01-10T22:24:05+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2016-08-25T02:03:28+00:00\" \/>\n<meta name=\"author\" content=\"Nate\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@n8finch\" \/>\n<meta name=\"twitter:site\" content=\"@n8finch\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nate\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/n8finch-site.site.strattic.io\/learning-new-things-grunt\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/n8finch-site.site.strattic.io\/learning-new-things-grunt\/\"},\"author\":{\"name\":\"Nate\",\"@id\":\"https:\/\/n8finch.local\/#\/schema\/person\/619068414583ca3c43bb135af49a47ce\"},\"headline\":\"Learning New Things: Grunt\",\"datePublished\":\"2016-01-10T22:24:05+00:00\",\"dateModified\":\"2016-08-25T02:03:28+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/n8finch-site.site.strattic.io\/learning-new-things-grunt\/\"},\"wordCount\":767,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/n8finch.local\/#\/schema\/person\/619068414583ca3c43bb135af49a47ce\"},\"articleSection\":[\"20 Hours Ahead\",\"Blog\",\"Web Development\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/n8finch-site.site.strattic.io\/learning-new-things-grunt\/\",\"url\":\"https:\/\/n8finch-site.site.strattic.io\/learning-new-things-grunt\/\",\"name\":\"Learning New Things: Grunt | Nate Finch\",\"isPartOf\":{\"@id\":\"https:\/\/n8finch.local\/#website\"},\"datePublished\":\"2016-01-10T22:24:05+00:00\",\"dateModified\":\"2016-08-25T02:03:28+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/n8finch-site.site.strattic.io\/learning-new-things-grunt\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/n8finch-site.site.strattic.io\/learning-new-things-grunt\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/n8finch-site.site.strattic.io\/learning-new-things-grunt\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/n8finch.local\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Learning New Things: Grunt\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/n8finch.local\/#website\",\"url\":\"https:\/\/n8finch.local\/\",\"name\":\"Nate Finch\",\"description\":\"All the things, keeping it clever...🤓\",\"publisher\":{\"@id\":\"https:\/\/n8finch.local\/#\/schema\/person\/619068414583ca3c43bb135af49a47ce\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/n8finch.local\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/n8finch.local\/#\/schema\/person\/619068414583ca3c43bb135af49a47ce\",\"name\":\"Nate\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/n8finch.local\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/n8finch2024.local\/wp-content\/uploads\/2020\/11\/nate-pic_ykd6mq.jpg\",\"contentUrl\":\"https:\/\/n8finch2024.local\/wp-content\/uploads\/2020\/11\/nate-pic_ykd6mq.jpg\",\"width\":796,\"height\":792,\"caption\":\"Nate\"},\"logo\":{\"@id\":\"https:\/\/n8finch.local\/#\/schema\/person\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Learning New Things: Grunt | Nate Finch","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:\/\/n8finch-site.site.strattic.io\/learning-new-things-grunt\/","og_locale":"en_US","og_type":"article","og_title":"Learning New Things: Grunt | Nate Finch","og_description":"I’m still getting a handle on Grunt. As far as a build tool, I’ve not yet been able to wrap my head completely around it. Maybe I need a better tutorial, or maybe I just need to not get hung up on any task runner that isn’t working right (looking at you, livereload!). I’ll get […]","og_url":"https:\/\/n8finch-site.site.strattic.io\/learning-new-things-grunt\/","og_site_name":"Nate Finch","article_published_time":"2016-01-10T22:24:05+00:00","article_modified_time":"2016-08-25T02:03:28+00:00","author":"Nate","twitter_card":"summary_large_image","twitter_creator":"@n8finch","twitter_site":"@n8finch","twitter_misc":{"Written by":"Nate","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/n8finch-site.site.strattic.io\/learning-new-things-grunt\/#article","isPartOf":{"@id":"https:\/\/n8finch-site.site.strattic.io\/learning-new-things-grunt\/"},"author":{"name":"Nate","@id":"https:\/\/n8finch.local\/#\/schema\/person\/619068414583ca3c43bb135af49a47ce"},"headline":"Learning New Things: Grunt","datePublished":"2016-01-10T22:24:05+00:00","dateModified":"2016-08-25T02:03:28+00:00","mainEntityOfPage":{"@id":"https:\/\/n8finch-site.site.strattic.io\/learning-new-things-grunt\/"},"wordCount":767,"commentCount":1,"publisher":{"@id":"https:\/\/n8finch.local\/#\/schema\/person\/619068414583ca3c43bb135af49a47ce"},"articleSection":["20 Hours Ahead","Blog","Web Development"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/n8finch-site.site.strattic.io\/learning-new-things-grunt\/","url":"https:\/\/n8finch-site.site.strattic.io\/learning-new-things-grunt\/","name":"Learning New Things: Grunt | Nate Finch","isPartOf":{"@id":"https:\/\/n8finch.local\/#website"},"datePublished":"2016-01-10T22:24:05+00:00","dateModified":"2016-08-25T02:03:28+00:00","breadcrumb":{"@id":"https:\/\/n8finch-site.site.strattic.io\/learning-new-things-grunt\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/n8finch-site.site.strattic.io\/learning-new-things-grunt\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/n8finch-site.site.strattic.io\/learning-new-things-grunt\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/n8finch.local\/"},{"@type":"ListItem","position":2,"name":"Learning New Things: Grunt"}]},{"@type":"WebSite","@id":"https:\/\/n8finch.local\/#website","url":"https:\/\/n8finch.local\/","name":"Nate Finch","description":"All the things, keeping it clever...🤓","publisher":{"@id":"https:\/\/n8finch.local\/#\/schema\/person\/619068414583ca3c43bb135af49a47ce"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/n8finch.local\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/n8finch.local\/#\/schema\/person\/619068414583ca3c43bb135af49a47ce","name":"Nate","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/n8finch.local\/#\/schema\/person\/image\/","url":"https:\/\/n8finch2024.local\/wp-content\/uploads\/2020\/11\/nate-pic_ykd6mq.jpg","contentUrl":"https:\/\/n8finch2024.local\/wp-content\/uploads\/2020\/11\/nate-pic_ykd6mq.jpg","width":796,"height":792,"caption":"Nate"},"logo":{"@id":"https:\/\/n8finch.local\/#\/schema\/person\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/n8finch2024.local\/wp-json\/wp\/v2\/posts\/819"}],"collection":[{"href":"https:\/\/n8finch2024.local\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/n8finch2024.local\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/n8finch2024.local\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/n8finch2024.local\/wp-json\/wp\/v2\/comments?post=819"}],"version-history":[{"count":7,"href":"https:\/\/n8finch2024.local\/wp-json\/wp\/v2\/posts\/819\/revisions"}],"predecessor-version":[{"id":1141,"href":"https:\/\/n8finch2024.local\/wp-json\/wp\/v2\/posts\/819\/revisions\/1141"}],"wp:attachment":[{"href":"https:\/\/n8finch2024.local\/wp-json\/wp\/v2\/media?parent=819"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/n8finch2024.local\/wp-json\/wp\/v2\/categories?post=819"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/n8finch2024.local\/wp-json\/wp\/v2\/tags?post=819"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}