Skip to content

Instantly share code, notes, and snippets.

@lonelydatum
Created February 9, 2015 19:26
Show Gist options
  • Save lonelydatum/150797b600184e165d05 to your computer and use it in GitHub Desktop.
Save lonelydatum/150797b600184e165d05 to your computer and use it in GitHub Desktop.
grunt
'use strict';
var
LIVERELOAD_PORT = 35729,
lrSnippet = require('connect-livereload')({ port: LIVERELOAD_PORT }),
mountFolder = function( connect, dir ) {
return connect.static(require('path').resolve(dir));
};
module.exports = function( grunt ) {
// load all grunt tasks
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-open');
grunt.loadNpmTasks('grunt-text-replace');
grunt.initConfig({
'replace': {
example: {
src: ['src/*'],
dest: 'dist/',
replacements: [{
from: 'bower_components',
to: '..'
}]
}
},
watch: {
livereload: {
files: [
'{,*/}*.html',
'static/{,*/}*.{css,js,png,jpg,gif,svg}'
],
tasks: [],
options: {
livereload: LIVERELOAD_PORT
}
}
},
connect: {
options: {
port: 9000,
hostname: '0.0.0.0'
},
livereload: {
options: {
middleware: function( connect ) {
return [
lrSnippet,
mountFolder(connect, './')
];
}
}
}
},
open: {
server: {
url: 'http://localhost:<%= connect.options.port %>'
}
}
});
// grunt.registerTask('build', ['replace']);
grunt.registerTask('server', function() {
grunt.task.run([
'connect:livereload',
'open',
'watch'
]);
});
grunt.registerTask('default', [ 'server' ]);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment