Skip to content

Instantly share code, notes, and snippets.

@davidvanleeuwen
Last active December 11, 2015 13:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidvanleeuwen/4606082 to your computer and use it in GitHub Desktop.
Save davidvanleeuwen/4606082 to your computer and use it in GitHub Desktop.
My Gruntfile for projects (still a work in progress)

##David's Gruntfile

  • Compiles Coffee, SASS, handlebar templates with a watcher
  • Uses RequireJS
  • Uses LiveReload

##Folder structure

- app
-- scripts
--- main.coffee
-- stylesheets
-- templates

- dist
-- scripts
-- stylesheets
-- index.html

##Tasks

###Starting all tasks combined This starts the server, watcher and get things going.

grunt server

'use strict'
module.exports = (grunt) ->
grunt.initConfig
open:
default:
url: 'http://localhost:5000'
reload:
port: 5000
proxy:
host: 'localhost'
port: 8000
connect:
default:
options:
base: './dist'
coffee:
compile:
files:
grunt.file.expandMapping(['app/scripts/**/*.coffee'], 'dist/scripts/',
rename: (destBase, destPath) ->
return destBase + destPath.slice(12, destPath.length).replace(/\.coffee$/, '.js')
)
sass:
options:
compass: true
compile:
files:
'dist/stylesheets/main.css': 'app/stylesheets/main.sass'
# Todo: change this to hamlc
handlebars:
compile:
options:
namespace: 'JST'
processName: (filename) ->
filename.substr(filename.lastIndexOf('/')+1, filename.length)
files:
'dist/scripts/templates.js': 'app/templates/**/*.hbs'
# Todo: use require-cs instead
requirejs:
compile:
options:
name: "main"
baseUrl: "./dist/scripts/"
mainConfigFile: "./dist/scripts/main.js"
optimize: "none"
out: "./dist/scripts/app.js"
watch:
default:
files: ['dist/index.html', 'app/scripts/**/*.coffee', 'app/stylesheets/**/*.sass', 'app/templates/**/*.hbs']
tasks: ['sass', 'coffee', 'handlebars', 'requirejs', 'reload']
grunt.loadNpmTasks 'grunt-contrib-connect'
grunt.loadNpmTasks 'grunt-contrib-coffee'
grunt.loadNpmTasks 'grunt-contrib-sass'
grunt.loadNpmTasks 'grunt-contrib-watch'
grunt.loadNpmTasks 'grunt-contrib-handlebars'
grunt.loadNpmTasks 'grunt-open'
grunt.loadNpmTasks 'grunt-reload'
grunt.loadNpmTasks 'grunt-contrib-requirejs'
grunt.registerTask 'build', ['coffee', 'sass', 'requirejs']
grunt.registerTask 'server', ['connect', 'open', 'reload', 'build', 'watch']
<html>
<head>
<script src="scripts/templates.js" type="text/javascript"></script>
<script data-main="scripts/app" src="scripts/vendor/require.js"></script>
</head>
<body>
</body>
</html>
{
"name": "Your project",
"version": "0.0.1",
"description": "My project uses David's Gruntfile",
"dependencies": {
"grunt": "~0.4.0rc5",
"grunt-contrib-coffee": "git+ssh://git@github.com:gruntjs/grunt-contrib-coffee.git#2a867a1377",
"grunt-contrib-sass": "git+ssh://git@github.com:gruntjs/grunt-contrib-sass.git",
"grunt-contrib-watch": "0.2.x",
"grunt-contrib-connect": "0.1.x",
"grunt-contrib-handlebars": "git+ssh://git@github.com:gruntjs/grunt-contrib-handlebars.git",
"grunt-open": "0.1.0",
"grunt-reload": "git+ssh://git@github.com:webxl/grunt-reload.git",
"grunt-contrib-requirejs": "git+ssh://git@github.com/gruntjs/grunt-contrib-requirejs.git"
},
"devDependencies": {},
"author": "David van Leeuwen"
}
@greaterweb
Copy link

I've been playing around with GruntJS 0.4 and was not able to get the grunt-reload task working. Did you have success with this setup?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment