Skip to content

Instantly share code, notes, and snippets.

@Fusselwurm
Created October 6, 2013 17:44
Show Gist options
  • Save Fusselwurm/6856925 to your computer and use it in GitHub Desktop.
Save Fusselwurm/6856925 to your computer and use it in GitHub Desktop.
gruntJS quickstart w/ jshint execution on code change

install node, npm globally

FILE="~/Downloads/node-v0.10.20-linux-x64.tar.gz"

sudo tar -xzf $FILE -C /opt/ sudo su cd /usr/local/bin ln -s /opt/node-v0.10.20-linux-x64/bin/node node # possibly add js, nodejs as aliases ln -s /opt/node-v0.10.20-linux-x64/bin/npm npm

in your respective project root:

  • create minimal package.json (see npm docs), if not yet existing

  • local install grunt & plugins you want:

    npm install grunt grunt-contrib-jshint grunt-contrib-watch --save-dev

  • create and edit Gruntfile.js. example:

module.exports = function(grunt) {

	// Project configuration.
	grunt.initConfig({
		pkg: grunt.file.readJSON('package.json'),
		jshint: {
			def: ['src/js/main.js', 'src/js/presets.js'] // note: wildcards possible here
		},
		watch: {
			files: ['src/js/**'],
			tasks: ['jshint']
		}
	});

	grunt.loadNpmTasks('grunt-contrib-jshint'); // load plugin
	grunt.loadNpmTasks('grunt-contrib-watch');

	grunt.registerTask('default', ['jshint']); // set magic default tasks

};
  • run grunt whenever you want with either
	grunt
	grunt jshint
	grunt watch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment