Skip to content

Instantly share code, notes, and snippets.

@andrewmartin
Created April 8, 2014 17:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewmartin/10161453 to your computer and use it in GitHub Desktop.
Save andrewmartin/10161453 to your computer and use it in GitHub Desktop.
A nice gruntfile
"use strict"
module.exports = (grunt) ->
# load all grunt tasks
require("matchdep").filterDev("grunt-*").forEach grunt.loadNpmTasks
config =
assets: "assets"
dist: "public"
require('time-grunt')(grunt)
# config
grunt.initConfig
watch:
options:
livereload: false
spawn: false
images:
files: ["assets/images/**/*"]
tasks: ['copy']
"sass-application":
livereload: false
files: [
"assets/styles/application.scss",
"assets/styles/**/*.scss"
]
tasks: ["sass:application"]
"sass-dashboard":
livereload: false
files: [
"assets/styles/dashboard.scss",
"assets/styles/**/*.scss"
]
tasks: ["sass:dashboard"]
vendor:
files: [
"assets/scripts/vendor/*.js"
]
tasks: ['concat', 'uglify']
coffee:
files: ["assets/scripts/**/*.coffee"]
tasks: ["coffee", "concat"]
livereload:
files: ["*.html", "*.php", "public/images/**/*.{png,jpg,jpeg,gif,webp,svg}"]
# sass compilation
# unused as of 3/11
sass:
application:
options:
outputStyle: 'expanded'
lineNumbers: true
sourceComments: 'map'
files:
'public/css/application.css': 'assets/styles/application.scss'
dashboard:
options:
outputStyle: 'expanded'
lineNumbers: true
sourceComments: 'map'
files:
'public/css/dashboard.css': 'assets/styles/dashboard.scss'
# style injector
# soft reload of css (fast!)
styleinjector:
files:
src: 'public/css/application.css'
options:
watchTask: false
debugInfo: true
# combine files
# to a single js or css file
concat:
# # this may be overkill;
# # maybe just have the coffee output to public/
"application-js":
src: [
"assets/scripts/app/**/*.js"
"assets/scripts/application.js"
]
dest: "public/scripts/application.js"
# load in vendor js libraries
"vendor-js":
src: [
"assets/components/modernizr/modernizr.js"
"assets/components/underscore/underscore.js"
"assets/components/jquery-dotimeout/jquery.ba-dotimeout.js"
"assets/components/jquery.easing/js/jquery.easing.min.js"
"assets/components/dropit/dropit.js"
"assets/components/jquery.uniform/jquery.uniform.js"
"assets/components/jquery/jquery-migrate.min.js"
"assets/components/bootstrap/dist/js/bootstrap.js"
"assets/scripts/vendor/*.js"
]
dest: 'public/scripts/vendor.js'
# load in vendor styles
# we should probably just use sass to import them...
# compiles all coffeescript 1 to 1
coffee:
dev:
options:
sourceMap: true
expand: true
cwd: "assets/scripts"
src: "**/*.coffee"
dest: "assets/scripts"
ext: ".js"
# fonts and svg files need to be copied to public folder
# since they are not compressed with any other tasks.
copy:
fonts:
files: [
expand: true
src: 'assets/fonts/**/*.{eot,svg,ttf,woff,otf}'
dest: 'public/fonts/'
flatten: true
]
"font-awesome":
files: [
expand: true
src: 'assets/components/font-awesome/fonts/**/*.{eot,svg,ttf,woff,otf}'
dest: 'public/fonts/'
flatten: true
]
images:
files: [
expand: true
cwd: "assets"
src: "images/**/*.{png,jpg,jpeg,gif,svg}"
dest: "public"
]
# public:
# files: [
# expand: true
# cwd: "public"
# src: ["*", "**/*"]
# dest: "_styleguide/dist"
# ]
kss:
options:
template: 'assets/vendor/styleguide-template'
styles: 'assets/styles/application.scss'
includeType: 'scss'
includePath: ['assets/styles/application.scss']
dist:
files:
'_styleguide': ["assets/styles"]
# minification and beautification tasks
# minify and compress css
cssmin:
options:
report: 'min'
banner: "/* minified via grunt task. Check Gruntfile.coffee for more info. */"
app:
files: "public/css/application.min.css": "public/css/application.css"
# vendor:
# files: "public/css/vendor.min.css": "public/css/vendor.css"
# uglify pages and vendor javsacript files
uglify:
"application-js":
options:
report: 'min'
files:
'public/scripts/application.min.js': [
'public/scripts/application.js'
]
vendor:
options:
report: 'min'
files:
'public/scripts/vendor.min.js': [
'public/scripts/vendor.js'
]
# for deployments
compress:
archive:
options:
archive: ".tmp/archive.zip"
files:
src: ['./**/*', '!./assets/**','!./db/**','!./node_modules/**']
dist:
options: mode: 'gzip'
expand: true
cwd: 'public/scripts'
src: "**/*.js"
dest: "public/scripts"
# clean
# to clean up the public/ dir and _styleguide dir
# this removes all files in there!
clean:
all: ["public/**/*", "_styleguide"]
# concurrent
# let's run some tasks simultaneously
concurrent:
build: ['copy']
styles: ['sass:application']
compress: ['uglify', 'cssmin']
sftp:
deploy:
files:
"./": "{**/*, !assets/}"
# Tasks
grunt.registerTask('build', ['coffee', 'sass', 'concurrent:build', 'concat', 'concurrent:compress', 'copy'])
grunt.registerTask('zip', ['compress:zip'])
grunt.registerTask('deploy', ['build', 'sftp:deploy'])
grunt.registerTask('styleguide', ['kss', 'sass'])
grunt.registerTask('default', ['coffee', 'sass', 'concurrent:build', 'concat', 'concurrent:compress', 'watch'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment