Skip to content

Instantly share code, notes, and snippets.

@nitinhayaran
Created May 18, 2013 07:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nitinhayaran/5603583 to your computer and use it in GitHub Desktop.
Save nitinhayaran/5603583 to your computer and use it in GitHub Desktop.
Sample Gruntfile.js
'use strict';
var LIVERELOAD_PORT = 35729;
var lrSnippet = require('connect-livereload')({port: LIVERELOAD_PORT});
var mountFolder = function (connect, dir) {
return connect.static(require('path').resolve(dir));
};
// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
// use this if you want to recursively match all subfolders:
// 'test/spec/**/*.js'
module.exports = function (grunt) {
// load all grunt tasks
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
grunt.initConfig({
watch: {
options: {
nospawn: true
},
less: {
files: ['app/styles/*.less'],
tasks: ['less:server']
},
livereload: {
options: {
livereload: LIVERELOAD_PORT
},
files: [
'app/*.html',
'app/styles/{,*/}*.css',
'app/scripts/{,*/}*.js',
'app/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
]
}
},
connect: {
options: {
port: 9000,
// change this to '0.0.0.0' to access the server from outside
hostname: 'localhost'
},
livereload: {
options: {
middleware: function (connect) {
return [
mountFolder(connect, 'app'),
lrSnippet
];
}
}
}
},
open: {
server: {
path: 'http://localhost:<%= connect.options.port %>'
}
},
less: {
server: {
options: {
paths: ['app/components/bootstrap/less', 'app/styles']
},
files: {
'app/styles/main.css': 'app/styles/main.less'
}
}
}
});
grunt.registerTask('server', function (target) {
grunt.task.run([
'less:server',
'connect:livereload',
'open',
'watch'
]);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment