Last active
December 14, 2015 08:49
-
-
Save jonathanmoore/5060750 to your computer and use it in GitHub Desktop.
A sample Grunt file to jshint, uglify, watch (regarde), connect a local server, and live reload the files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var path = require('path'); | |
var lrSnippet = require('grunt-contrib-livereload/lib/utils').livereloadSnippet; | |
var folderMount = function folderMount(connect, point) { | |
return connect.static(path.resolve(point)); | |
}; | |
module.exports = function(grunt) { | |
// Project config | |
grunt.initConfig({ | |
pkg: grunt.file.readJSON('package.json'), | |
connect: { | |
livereload: { | |
options: { | |
port: 9001, | |
middleware: function(connect, options) { | |
return [lrSnippet, folderMount(connect, '.')] | |
} | |
} | |
} | |
}, | |
regarde: { | |
js: { | |
files: ['**/*.js', '!**/node_modules/**'], | |
tasks: ['jshint', 'uglify', 'livereload'], | |
}, | |
html: { | |
files: '**/*.html', | |
tasks: ['livereload'] | |
}, | |
css: { | |
files: '**/*.css', | |
tasks: ['livereload'] | |
} | |
}, | |
jshint: { | |
files: ['jquery.photosetGrid.js'] | |
}, | |
uglify: { | |
options: { | |
banner: '/**\n' + | |
' * <%= pkg.name %> - v<%= pkg.version %>\n' + | |
' * <%= grunt.template.today("yyyy-mm-dd") %>\n' + | |
' * <%= pkg.description %>\n' + | |
' * <%= pkg.repository.docs %>\n' + | |
' *\n' + | |
' * Copyright <%= grunt.template.today("yyyy") %> <%= pkg.author %>\n' + | |
' */\n' | |
}, | |
dist: { | |
files: { | |
'jquery.photosetGrid.min.js': ['jquery.photosetGrid.js'] | |
} | |
} | |
} | |
}); | |
// Load the grunt plugins | |
grunt.loadNpmTasks('grunt-regarde'); | |
grunt.loadNpmTasks('grunt-contrib-uglify'); | |
grunt.loadNpmTasks('grunt-contrib-jshint'); | |
grunt.loadNpmTasks('grunt-contrib-connect'); | |
grunt.loadNpmTasks('grunt-contrib-livereload'); | |
// Default task(s) | |
grunt.registerTask('default', ['jshint', 'uglify']); | |
grunt.registerTask('server', ['livereload-start', 'connect', 'regarde']); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
grunt
will simply jshint and uglify the jquery.photosetGrid.js file.grunt server
will start livereload, connect to localhost:9001, watch for file changes and process the Javascript files when needed.