Skip to content

Instantly share code, notes, and snippets.

@kamiyam
Last active Dec 14, 2015
Embed
What would you like to do?
grunt.js 0.4 beginning...

mkdir grunt0.4

cd grunt0.4

create file package.json, Gruntfile.js, index.html

npm install

grunt

browse http://localhost:9001

index.html file change and save

live reload !!

'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 configuration.
grunt.initConfig({
connect: {
options: {
port: 9000,
// change this to '0.0.0.0' to access the server from outside
hostname: 'localhost'
},
livereload: {
options: {
middleware: function(connect, options) {
return [lrSnippet, folderMount(connect, '.')];
}
}
}
},
// Configuration to be run (and then tested)
regarde: {
fred: {
files: '*.html',
tasks: ['livereload']
}
},
// browser open
open: {
server: {
path: 'http://localhost:<%= connect.options.port %>'
}
}
});
grunt.loadNpmTasks('grunt-regarde');
grunt.loadNpmTasks('grunt-open');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-livereload');
grunt.registerTask('default', ['livereload-start', 'connect', 'open', 'regarde']);
};
<!DOCTYPE HTML>
<html lang="ja_JP">
<head>
<meta charset="UTF-8">
</head>
<body>
Live reload!!
</body>
</html>
{
"name": "gruntjs0.4-beginning",
"version": "0.1.0",
"Dependencies": {},
"devDependencies": {
"grunt": "~0.4.0",
"grunt-contrib-connect": "~0.1.2",
"grunt-contrib-livereload": "~0.1.1",
"grunt-regarde": "~0.1.1",
"grunt-open": "~0.2.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment