Skip to content

Instantly share code, notes, and snippets.

@dan-palmer
Last active December 29, 2015 08:59
Show Gist options
  • Save dan-palmer/7647521 to your computer and use it in GitHub Desktop.
Save dan-palmer/7647521 to your computer and use it in GitHub Desktop.
Example Grunt File for Watching & Compiling .coffee files in a project
sourceFiles = [ '*.coffee', 'models/*.coffee', 'views/*.coffee' ]
fullPathSourceFiles = sourceFiles.map (f) -> "app/coffee/" + f
fullPathSpecFiles = sourceFiles.map (f) -> "specs/coffee/" + f
module.exports = (grunt) ->
grunt.initConfig
pkg: grunt.file.readJSON 'package.json'
watch:
coffee:
files: fullPathSourceFiles.concat(fullPathSpecFiles)
tasks: 'coffee'
coffee:
glob_to_multiple:
expand: true
cwd: 'app/coffee'
src: sourceFiles
dest: 'app/js'
ext: '.js'
specs:
files: grunt.file.expandMapping(fullPathSpecFiles, "", {
rename: (destBase, destPath) ->
destBase + destPath.replace(/\.coffee$/, ".js").replace(/coffee\//, "js/")
})
grunt.loadNpmTasks 'grunt-contrib-watch'
grunt.loadNpmTasks 'grunt-contrib-coffee'
grunt.registerTask 'default', ['coffee']
grunt.registerTask 'w', ['watch']
{
"name": "Test-Grunt",
"version": "0.1.0",
"devDependencies": {
"grunt": "~0.4.2",
"grunt-contrib-jshint": "~0.6.3",
"grunt-contrib-nodeunit": "~0.2.0",
"grunt-contrib-uglify": "~0.2.2",
"grunt-contrib-coffee": "~0.7.0",
"grunt-contrib-watch": "~0.5.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment