<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: SagarMajumdar</title>
    <description>The latest articles on DEV Community by SagarMajumdar (@sagarmajumdar).</description>
    <link>https://dev.to/sagarmajumdar</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F542841%2Febd4006c-aab1-4c27-9506-953493820578.png</url>
      <title>DEV Community: SagarMajumdar</title>
      <link>https://dev.to/sagarmajumdar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sagarmajumdar"/>
    <language>en</language>
    <item>
      <title>Starting with GRUNT</title>
      <dc:creator>SagarMajumdar</dc:creator>
      <pubDate>Fri, 18 Dec 2020 12:05:21 +0000</pubDate>
      <link>https://dev.to/sagarmajumdar/starting-with-grunt-3cjg</link>
      <guid>https://dev.to/sagarmajumdar/starting-with-grunt-3cjg</guid>
      <description>&lt;p&gt;Grunt is a task runner. Basically what Grunt does is automate some tasks like concatenating multiple files, converting LESS to CSS etc.&lt;br&gt;
In this post I will discuss the very fundamentals of Grunt.&lt;/p&gt;

&lt;p&gt;To Start using Grunt we first need to install it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;install grunt cli globally so that we can use it anywhere and do not need to install it whenever we create a project
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; npm install grunt-cli -g
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;create a package.json file
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;install grunt locally
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install grunt --save-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;&lt;p&gt;create a new file named Gruntfile.js. In this file  we control the configuration of plugins that we install and where we register the tasks.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We can install different plugins from the list available in &lt;a href="https://gruntjs.com/plugins"&gt;Link&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Eg: &lt;code&gt;npm install grunt-contrib-concat --save-dev&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;'contrib' suggests that it is maintained by the Grunt team.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Gruntfile.js&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module.exports = (grunt) =&amp;gt; {
    // configuration
    grunt.initConfig({
        // pass in options to plugins,  references to files etc
        // "concat"  -- anything after "grunt-contrib-"
        concat: {
            js: {
                src: ['js/a.js', 'js/b.js']
                // src: ['js/*.js']; -- * all js files in folder
                , dest: 'build/scripts.js'
            },
            css: {
                src: ['css/*.css'],
                dest: 'build/styles.css'
            }
        },
        uglify: {
            build: {
                files: [{
                    src: 'build/scripts.js',
                    dest: 'build/scripts_compressed' // if we write 'build/scripts.js' then it will overwrite 
                }]
            }
        },
        watch: {
            csswatch: {
                files: ['css/*.css']
            }
        },
        less: {
            build: {
                files: [{
                    src: 'css/less/xy.less',
                    dest: 'build/xyz.css'
                }]
            }
        },
        jshint: {
            all: ['js/*.js']

        },
        htmlmin: {
            files: {
                src: ['html/*.html'],
                dest: 'dist/',
                expand: true,
                flatten: true,
                ext: '.html',
                extDot: 'last'
            }

        }
    });


    //load plugin
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-less');
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-htmlmin');

};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;We can run by typing grunt run ... . Eg. &lt;code&gt;grunt run jshint&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The Net Ninja has some good beginner Grunt tutorials in Youtube which you can check out.&lt;/p&gt;

&lt;p&gt;I  hope following this article you can install Grunt and start with some basic task.&lt;/p&gt;

&lt;p&gt;Thanks for reading.&lt;/p&gt;

</description>
      <category>grunt</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
