Skip to content

Instantly share code, notes, and snippets.

@lbeschastny
Last active December 18, 2015 03:09
Show Gist options
  • Save lbeschastny/5716323 to your computer and use it in GitHub Desktop.
Save lbeschastny/5716323 to your computer and use it in GitHub Desktop.
'use strict'
config = require './config'
cache_lifetime = 10 # days
module.exports = (grunt) ->
grunt.loadNpmTasks 'grunt-s3'
grunt.loadNpmTasks 'grunt-contrib-concat'
grunt.loadNpmTasks 'grunt-contrib-clean'
grunt.loadNpmTasks 'grunt-contrib-uglify'
grunt.loadNpmTasks 'grunt-contrib-coffee'
grunt.initConfig
pkg: grunt.file.readJSON('package.json')
dirs:
dist: 'dist/'
s3: '/assets/0/<%= pkg.name %>/<%= pkg.version %>/'
coffee:
all:
files: [
expand: true,
cwd: 'assets/js/'
src: ['*.coffee']
dest: 'public/js/'
ext: '.js'
]
concat:
libs:
src: [
'components/jquery/jquery.js'
'libs/fotorama.js'
'libs/plusone.js'
]
dest: '<%= dirs.dist %>js/libs.js'
core:
src: ['public/js/*.js'] # * isn't a good idea here since the order of .js files is important
dest: '<%= dirs.dist %>js/core.js'
uglify:
libs:
mangle: toplevel: true
squeeze: dead_code: true
codegen: quote_keys: true
src: '<%= concat.libs.dest %>'
dest: '<%= concat.libs.dest %>'
core:
mangle: toplevel: true
squeeze: dead_code: true
codegen: quote_keys: true
src: '<%= concat.core.dest %>'
dest: '<%= concat.core.dest %>'
clean:
js: 'public/js'
dist: 'dist'
s3:
key: config.aws.access_key
secret: config.aws.secret_key
bucket: config.aws.bucket
access: 'public-read'
headers:
'Cache-Control': "public, max-age=#{60*60*24*cache_lifetime}"
upload: [
{
src: '<%= dirs.dist %>js/*'
dest: '<%= dirs.s3 %>js/'
gzip: true
}
]
grunt.registerTask "deploy", [
"clean"
"coffee"
"concat"
"uglify"
"s3"
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment