Coder Social home page Coder Social logo

grunt's Introduction

Simple Grunt Tutorial via Scotch.io

https://scotch.io/tutorials/a-simple-guide-to-getting-started-with-grunt

  • Grunt is a task runner that automates repetitive workflow tasks (linting and minifying JS files, compiling LESS and SASS files, minifying CSS files, watching files for changes and doing tasks, etc).

  • Node.js needs to be installed

    • Run node -v and npm -v to make sure they're installed
  • dist folder holds all final files (minified by Grunt) used for final site

  • src folder holds all original files

  • Gruntfile.js for our Grunt configuration

  • package.json for our npm package configuration

    • contrib-jshint validates files using jshint
    • contrib-uglify minifies JS files using UglifyJS
    • contrib-less compiles LESS files to CSS (use contrib-compass for SASS)
    • contrib-cssmin compresses CSS files
    • contrib-watch runs tasks whenever watched files are changed
  • Basic format for configuring packages:

    1. Call the name of the package (e.g. jshint)
    2. Set options if needed (usually found on the docs for each package).
    3. Create a build attribute and pass in files, directories, or anything else you want.
  • Different tasks for different environments (e.g. development and production)

    • Can define multiple tasks inside of each configuration in Gruntfile.js:
     // configure uglify to minify js files
     uglify: {
     	options: {
     		banner: '/\n <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> \n/\n'
     	},
     	dev: {
     		files: { 'dist/js/magic.min.js': ['src/js/magic.js', 'src/js/magic2.js'] }
     	},
     	production: {
     		 files: { 'dist/js/magic.min.js': 'src/**/*.js' }
     	}
     }
    
    • Create tasks for development and production in Gruntfile.js:
     // this task will only run the dev configuration
     grunt.registerTask('dev', ['jshint:dev', 'uglify:dev', 'cssmin:dev', 'less:dev']);
    
     // only run production configuration
     grunt.registerTask('production', ['jshint:production', 'uglify:production', 'cssmin:production', 'less:production']);
    
    • Call development or production by running grunt dev or grunt production in the command line
  • Command line commands:

    • grunt jshint
    • grunt uglify
    • grunt less
    • grunt cssmin
    • grunt (runs everything within 'default' task)
    • grunt dev (only run dev config)
    • grunt production (only run production config)
    • grunt watch
    • grunt imagemin

grunt's People

Contributors

bljohnson avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.