Skip to content

Instantly share code, notes, and snippets.

@antpaw
Created June 23, 2015 17:31
Show Gist options
  • Save antpaw/1d81a61ccd721d5f744d to your computer and use it in GitHub Desktop.
Save antpaw/1d81a61ccd721d5f744d to your computer and use it in GitHub Desktop.
Tasks for creating an assetpipline for Coffee (browserified) and SASS assets
'use strict'
module.exports = (grunt) ->
# Project configuration.
destCss = 'public/css/'
destJs = 'public/js/'
src = 'src/'
externalLibs = [ 'npm-zepto', 'jquery' ]
grunt.initConfig(
# Meta
pkg: grunt.file.readJSON('package.json')
banner:
'/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' + '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
'<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
'* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>; */\n'
# Helper
watch:
coffee:
files: src+'coffee/**/*.coffee'
#tasks: [ 'coffee:compile' ]
tasks: [ 'browserify:compile' ]
sass:
files: src+'sass/**/*.sass'
tasks: [ 'sass' ]
clean:
css: [ destCss ]
js: [ destJs ]
jshint:
options:
jshintrc: true
browser: true
test:
files:
cwd: destJs
src: [ '**/*.js', '!**/*.min.js' ]
# Stylesheets
sass: compile:
options:
sourcemap: 'none'
expand: true
cwd: src+'sass/assets/'
src: [ '**/*.sass' ]
dest: destCss
ext: '.css'
cssmin: target: files: [ {
expand: true
cwd: destCss
src: [ '**/*.css', '!**/*..min.css' ]
dest: destCss
ext: '.min.css'
} ]
# Javascript
# coffee: compile:
# expand: true
# cwd: src+'coffee/assets/'
# src: [ '**/*.coffee' ]
# dest: destJs
# ext: '.js'
browserify:
vendor:
options:
require: externalLibs
src: './'
dest: destJs+'vendor.js'
compile:
options:
transform: [ 'coffeeify' ]
external: externalLibs
expand: true
cwd: src+'coffee/assets/'
src: [ '**/*.coffee' ]
dest: destJs
ext: '.js'
uglify: target: files: [ {
expand: true
cwd: destJs
src: [ '**/*.js', '!**/*.min.js' ]
dest: destJs
ext: '.min.js'
} ]
)
grunt.loadNpmTasks 'grunt-contrib-clean'
grunt.loadNpmTasks 'grunt-contrib-coffee'
grunt.loadNpmTasks 'grunt-contrib-uglify'
grunt.loadNpmTasks 'grunt-contrib-jshint'
grunt.loadNpmTasks 'grunt-contrib-watch'
grunt.loadNpmTasks 'grunt-contrib-sass'
grunt.loadNpmTasks 'grunt-contrib-compass'
grunt.loadNpmTasks 'grunt-contrib-cssmin'
grunt.loadNpmTasks 'grunt-browserify'
grunt.registerTask 'build_css', [ 'clean:css', 'sass', 'cssmin' ]
grunt.registerTask 'build_js', [ 'clean:js', 'browserify:compile', 'browserify:vendor', 'uglify' ]
grunt.registerTask 'build_js_vendor', [ 'browserify:vendor' ]
grunt.registerTask 'build', [ 'build_js', 'build_css' ]
return
{
"title": "__project title__",
"name": "__project name__",
"version": "0.0.1",
"description": "asset management for __project title__",
"homepage": "http://__url__",
"author": {
"name": "Anton Pawlik",
"email": "anton.pawlik@gmail.com"
},
"engines": {
"node": ">= 0.8.0"
},
"scripts": {},
"devDependencies": {
"coffeeify": "1.1.0",
"grunt": "0.4.5",
"grunt-browserify": "3.8.0",
"grunt-contrib-clean": "0.6.0",
"grunt-contrib-coffee": "0.13.0",
"grunt-contrib-cssmin": "0.12.3",
"grunt-contrib-jshint": "0.11.2",
"grunt-contrib-sass": "0.9.2",
"grunt-contrib-uglify": "0.9.1",
"grunt-contrib-watch": "0.6.1",
"jquery": "2.1.4"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment