Skip to content

Instantly share code, notes, and snippets.

@bcherny
Last active December 25, 2015 20:29
Show Gist options
  • Save bcherny/7034860 to your computer and use it in GitHub Desktop.
Save bcherny/7034860 to your computer and use it in GitHub Desktop.
Gruntfile for compiling, wrapping with UMD, and minifying dependency-free coffeescripts. Names the file after its current directory, and loads dependencies from `package.json`.
module.exports = (grunt) ->
nameParts = __dirname.split '/'
name = nameParts[nameParts.length - 1]
pkg = grunt.file.readJSON 'package.json'
deps = grunt.util._.keys pkg.dependencies
config =
pkg: pkg
bytesize:
all:
src: []
coffee:
compile:
files: {}
options:
bare: true
nodeunit:
all: ['test/test.js']
uglify:
options:
mangle:
toplevel: true
compress:
dead_code: true
unused: true
join_vars: true
comments: false
standard:
files: {}
umd:
all: {}
# configure coffee, uglify, umd
config.bytesize.all.src = [name + '.js', name + '.min.js']
config.coffee.compile.files[name + '.js'] = name + '.coffee'
config.uglify.standard.files[name + '.min.js'] = [name + '.js']
config.umd.all =
src: name + '.js'
objectToExport: name.replace '-', ''
amdModuleId: name
globalAlias: name
deps:
default: deps or []
# load config
grunt.config.init config
# load tasks
grunt.loadNpmTasks 'grunt-bytesize'
grunt.loadNpmTasks 'grunt-contrib-coffee'
grunt.loadNpmTasks 'grunt-contrib-nodeunit'
grunt.loadNpmTasks 'grunt-contrib-uglify'
grunt.loadNpmTasks 'grunt-umd'
# register tasks
grunt.registerTask 'default', ['coffee', 'umd', 'nodeunit', 'uglify', 'bytesize']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment