{"id":11691,"date":"2014-02-06T22:56:18","date_gmt":"2014-02-06T17:26:18","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=11691"},"modified":"2014-02-07T15:58:51","modified_gmt":"2014-02-07T10:28:51","slug":"getting-started-with-grunt","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/getting-started-with-grunt\/","title":{"rendered":"Getting Started with Grunt:Task Runner"},"content":{"rendered":"<p>I was working on one of my projects which involved multiple task execution on regular basis. Well, I think that many of us have faced similar issues on their projects which increases our work and making it more time-consuming and increased work. Working in a community where people are actively developing tools to automate tedious processes, you assumes to have some tools to automate and speed up this process too.<\/p>\n<p>For such scenarios, we have\u00a0<strong>Grunt, <\/strong>to the rescue. I loved the way it made my work flow so easy.<\/p>\n<p>Grunt already has a lot of plugins for the task like compiling less CSS, command shell, minifying\u00a0CSS etc., or you can also create our own Grunt plugin for tasks which are repetitive or used on daily basis.<\/p>\n<p>Now we will understand grunt with the help of a plugin called &#8220;cssmin&#8221;, used to minify CSS files.<\/p>\n<p>Lets start with the setting up of grunt<\/p>\n<ol>\n<li>Installing grunt-cli globally\n<pre><code>npm install -g grunt-cli<\/code><\/pre>\n<\/li>\n<li>In your project directory install grunt and grunt plugin command\n<pre><code>npm install grunt --save-dev <\/code>\r\n<code>npm install grunt-contrib-mincss --save-dev\u00a0<\/code><\/pre>\n<div>\u00a0It will add grunt and grunt plugins in devDependencies\u00a0in package.json.<\/div>\n<\/li>\n<li>Gruntfile.js or Gruntfile.coffee<br \/>\n<strong>Gruntfile\u00a0<\/strong>must be there in project root directory after .json\u00a0package.This file contains<\/p>\n<ul>\n<li>The &#8220;wrapper&#8221; function<\/li>\n<li>Project and task configuration<\/li>\n<li>Loading Grunt plugins and tasks<\/li>\n<li>Custom tasks<br \/>\nGruntfile must look like:<\/li>\n<li>[js]<br \/>\n module.exports=function(grunt){<br \/>\n \/\/here grunt code comes<br \/>\n \/\/project configuration<br \/>\n grunt.initConfig({<br \/>\n      pkg:\u00a0grunt.file.readJSON(&#8216;package.json&#8217;),<br \/>\n      cssmin:{<br \/>\n            minify: {<br \/>\n            expand: true,<br \/>\n            cwd: &#8216;public\/stylesheets\/css\/&#8217;,<br \/>\n            src: [&#8216;*.css&#8217;, &#8216;!*.min.css&#8217;],<br \/>\n            dest: &#8216;public\/stylesheets\/mincss\/&#8217;,<br \/>\n            ext: &#8216;.min.css&#8217;<br \/>\n                     }<br \/>\n            }<br \/>\n       });<br \/>\n\/\/load grunt plugins and register tasks<br \/>\ngrunt.loadNpmTasks(&quot;grunt-contrib-cssmin&quot;);<br \/>\ngrunt.registerTask(&#8216;default&#8217;, [&#8216;cssmin&#8217;]);<br \/>\n[\/js]<\/p>\n<p><span style=\"font-family: 'Courier 10 Pitch', Courier, monospace;font-size: 13px;font-style: normal;line-height: 1.5\"><br \/>\n<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><span>Now its your turn to be the magician. Open your terminal, go to your project directory and write\u00a0<\/span><\/p>\n<p><span style=\"background-color: #f4f4f4\"> <code>grunt cssmin<\/code><\/span><\/p>\n<p>All your minified css will be generated in destination directory which you have mentioned in Gruntfile.js.<\/p>\n<p>Hope it will make your work flow easier \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was working on one of my projects which involved multiple task execution on regular basis. Well, I think that many of us have faced similar issues on their projects which increases our work and making it more time-consuming and increased work. Working in a community where people are actively developing tools to automate tedious [&hellip;]<\/p>\n","protected":false},"author":66,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":1,"footnotes":""},"categories":[1185],"tags":[245,1307,1306,55,1124],"class_list":["post-11691","post","type-post","status-publish","format-standard","hentry","category-node-js-2","tag-css","tag-cssmin","tag-gruntjs","tag-javascript","tag-node-js"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"I was working on one of my projects which involved multiple task execution on regular basis. Well, I think that many of us have faced similar issues on their projects which increases our work and making it more time-consuming and increased work. Working in a community where people are actively developing tools to automate tedious\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Sahil Chitkara\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.tothenew.com\/blog\/getting-started-with-grunt\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"TO THE NEW BLOG\" \/>\n\t\t<meta property=\"og:type\" content=\"blog\" \/>\n\t\t<meta property=\"og:title\" content=\"Getting Started with Grunt:Task Runner | TO THE NEW Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"I was working on one of my projects which involved multiple task execution on regular basis. Well, I think that many of us have faced similar issues on their projects which increases our work and making it more time-consuming and increased work. Working in a community where people are actively developing tools to automate tedious\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.tothenew.com\/blog\/getting-started-with-grunt\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@tothenew\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Getting Started with Grunt:Task Runner | TO THE NEW Blog\" \/>\n\t\t<meta name=\"twitter:description\" content=\"I was working on one of my projects which involved multiple task execution on regular basis. Well, I think that many of us have faced similar issues on their projects which increases our work and making it more time-consuming and increased work. Working in a community where people are actively developing tools to automate tedious\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/getting-started-with-grunt\\\/#article\",\"name\":\"Getting Started with Grunt:Task Runner | TO THE NEW Blog\",\"headline\":\"Getting Started with Grunt:Task Runner\",\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/sahil\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"},\"datePublished\":\"2014-02-06T22:56:18+05:30\",\"dateModified\":\"2014-02-07T15:58:51+05:30\",\"inLanguage\":\"en-US\",\"commentCount\":1,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/getting-started-with-grunt\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/getting-started-with-grunt\\\/#webpage\"},\"articleSection\":\"Node.js, css, cssmin, gruntjs, javascript, node.js\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/getting-started-with-grunt\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/node-js-2\\\/#listItem\",\"name\":\"Node.js\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/node-js-2\\\/#listItem\",\"position\":2,\"name\":\"Node.js\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/node-js-2\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/getting-started-with-grunt\\\/#listItem\",\"name\":\"Getting Started with Grunt:Task Runner\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/getting-started-with-grunt\\\/#listItem\",\"position\":3,\"name\":\"Getting Started with Grunt:Task Runner\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/node-js-2\\\/#listItem\",\"name\":\"Node.js\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\",\"name\":\"TO THE NEW Blog\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/sahil\\\/#author\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/sahil\\\/\",\"name\":\"Sahil Chitkara\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/getting-started-with-grunt\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b91bdfc498b589781ffafd1e1add2085872ca7c745e54e167c93abc1853439f4?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Sahil Chitkara\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/getting-started-with-grunt\\\/#webpage\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/getting-started-with-grunt\\\/\",\"name\":\"Getting Started with Grunt:Task Runner | TO THE NEW Blog\",\"description\":\"I was working on one of my projects which involved multiple task execution on regular basis. Well, I think that many of us have faced similar issues on their projects which increases our work and making it more time-consuming and increased work. Working in a community where people are actively developing tools to automate tedious\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/getting-started-with-grunt\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/sahil\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/sahil\\\/#author\"},\"datePublished\":\"2014-02-06T22:56:18+05:30\",\"dateModified\":\"2014-02-07T15:58:51+05:30\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\",\"name\":\"TO THE NEW Blog\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Getting Started with Grunt:Task Runner | TO THE NEW Blog","description":"I was working on one of my projects which involved multiple task execution on regular basis. Well, I think that many of us have faced similar issues on their projects which increases our work and making it more time-consuming and increased work. Working in a community where people are actively developing tools to automate tedious","canonical_url":"https:\/\/www.tothenew.com\/blog\/getting-started-with-grunt\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.tothenew.com\/blog\/getting-started-with-grunt\/#article","name":"Getting Started with Grunt:Task Runner | TO THE NEW Blog","headline":"Getting Started with Grunt:Task Runner","author":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/sahil\/#author"},"publisher":{"@id":"https:\/\/www.tothenew.com\/blog\/#organization"},"datePublished":"2014-02-06T22:56:18+05:30","dateModified":"2014-02-07T15:58:51+05:30","inLanguage":"en-US","commentCount":1,"mainEntityOfPage":{"@id":"https:\/\/www.tothenew.com\/blog\/getting-started-with-grunt\/#webpage"},"isPartOf":{"@id":"https:\/\/www.tothenew.com\/blog\/getting-started-with-grunt\/#webpage"},"articleSection":"Node.js, css, cssmin, gruntjs, javascript, node.js"},{"@type":"BreadcrumbList","@id":"https:\/\/www.tothenew.com\/blog\/getting-started-with-grunt\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog#listItem","position":1,"name":"Home","item":"https:\/\/www.tothenew.com\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/node-js-2\/#listItem","name":"Node.js"}},{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/node-js-2\/#listItem","position":2,"name":"Node.js","item":"https:\/\/www.tothenew.com\/blog\/category\/node-js-2\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/getting-started-with-grunt\/#listItem","name":"Getting Started with Grunt:Task Runner"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/getting-started-with-grunt\/#listItem","position":3,"name":"Getting Started with Grunt:Task Runner","previousItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/node-js-2\/#listItem","name":"Node.js"}}]},{"@type":"Organization","@id":"https:\/\/www.tothenew.com\/blog\/#organization","name":"TO THE NEW Blog","url":"https:\/\/www.tothenew.com\/blog\/"},{"@type":"Person","@id":"https:\/\/www.tothenew.com\/blog\/author\/sahil\/#author","url":"https:\/\/www.tothenew.com\/blog\/author\/sahil\/","name":"Sahil Chitkara","image":{"@type":"ImageObject","@id":"https:\/\/www.tothenew.com\/blog\/getting-started-with-grunt\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/b91bdfc498b589781ffafd1e1add2085872ca7c745e54e167c93abc1853439f4?s=96&d=mm&r=g","width":96,"height":96,"caption":"Sahil Chitkara"}},{"@type":"WebPage","@id":"https:\/\/www.tothenew.com\/blog\/getting-started-with-grunt\/#webpage","url":"https:\/\/www.tothenew.com\/blog\/getting-started-with-grunt\/","name":"Getting Started with Grunt:Task Runner | TO THE NEW Blog","description":"I was working on one of my projects which involved multiple task execution on regular basis. Well, I think that many of us have faced similar issues on their projects which increases our work and making it more time-consuming and increased work. Working in a community where people are actively developing tools to automate tedious","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.tothenew.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/www.tothenew.com\/blog\/getting-started-with-grunt\/#breadcrumblist"},"author":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/sahil\/#author"},"creator":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/sahil\/#author"},"datePublished":"2014-02-06T22:56:18+05:30","dateModified":"2014-02-07T15:58:51+05:30"},{"@type":"WebSite","@id":"https:\/\/www.tothenew.com\/blog\/#website","url":"https:\/\/www.tothenew.com\/blog\/","name":"TO THE NEW Blog","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.tothenew.com\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"TO THE NEW BLOG","og:type":"blog","og:title":"Getting Started with Grunt:Task Runner | TO THE NEW Blog","og:description":"I was working on one of my projects which involved multiple task execution on regular basis. Well, I think that many of us have faced similar issues on their projects which increases our work and making it more time-consuming and increased work. Working in a community where people are actively developing tools to automate tedious","og:url":"https:\/\/www.tothenew.com\/blog\/getting-started-with-grunt\/","og:image":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","og:image:secure_url":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","twitter:card":"summary","twitter:site":"@tothenew","twitter:title":"Getting Started with Grunt:Task Runner | TO THE NEW Blog","twitter:description":"I was working on one of my projects which involved multiple task execution on regular basis. Well, I think that many of us have faced similar issues on their projects which increases our work and making it more time-consuming and increased work. Working in a community where people are actively developing tools to automate tedious","twitter:image":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png"},"aioseo_meta_data":{"post_id":"11691","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"created":"2021-04-30 08:05:11","updated":"2024-02-29 10:49:22","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.tothenew.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.tothenew.com\/blog\/category\/node-js-2\/\" title=\"Node.js\">Node.js<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tGetting Started with Grunt:Task Runner\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.tothenew.com\/blog"},{"label":"Node.js","link":"https:\/\/www.tothenew.com\/blog\/category\/node-js-2\/"},{"label":"Getting Started with Grunt:Task Runner","link":"https:\/\/www.tothenew.com\/blog\/getting-started-with-grunt\/"}],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/11691","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/66"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=11691"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/11691\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=11691"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=11691"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=11691"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}