Skip to content

Instantly share code, notes, and snippets.

@qrg
Created December 25, 2013 10:08
Show Gist options
  • Save qrg/8121906 to your computer and use it in GitHub Desktop.
Save qrg/8121906 to your computer and use it in GitHub Desktop.
module.exports = (grunt) ->
target = grunt.option('target') || 'dev'
grunt.initConfig
pkg: grunt.file.readJSON 'package.json'
dir:
src : 'src/'
dist : 'dist/'
test : '<%= dir.src %>/test/'
doc : 'docs/'
components: 'bower_components/'
uglifyFiles: [
'<%= dir.src %>js/console.js'
# vendor ----------------------------------------------
'<%= dir.src %>js/vendor/underscore.js'
'<%= dir.src %>js/vendor/handlebars.runtime.js'
'<%= dir.src %>js/vendor/backbone.js'
'<%= dir.src %>js/vendor/backbone.marionette.js'
'<%= dir.src %>js/vendor/moment/moment.js'
'<%= dir.src %>js/vendor/livestamp.js'
'<%= dir.src %>js/vendor/spin.js'
'<%= dir.src %>js/vendor/jquery.spin.js'
'<%= dir.src %>js/vendor/jquery.mousewheel.js'
'<%= dir.src %>js/vendor/perfect-scrollbar.js'
'<%= dir.src %>js/vendor/jquery.transit.js'
'<%= dir.src %>js/vendor/bootstrap/transition.js'
'<%= dir.src %>js/vendor/bootstrap/alert.js'
'<%= dir.src %>js/vendor/bootstrap/button.js'
'<%= dir.src %>js/vendor/bootstrap/carousel.js'
'<%= dir.src %>js/vendor/bootstrap/collapse.js'
'<%= dir.src %>js/vendor/bootstrap/dropdown.js'
'<%= dir.src %>js/vendor/bootstrap-modal/bootstrap-modalmanager.js'
'<%= dir.src %>js/vendor/bootstrap-modal/bootstrap-modal.js'
'<%= dir.src %>js/vendor/bootstrap/tooltip.js'
'<%= dir.src %>js/vendor/bootstrap/popover.js'
'<%= dir.src %>js/vendor/bootstrap/scrollspy.js'
'<%= dir.src %>js/vendor/bootstrap/tab.js'
'<%= dir.src %>js/vendor/bootstrap/affix.js'
# app -------------------------------------------------
'<%= dir.src %>js/app/namespace.js'
'<%= dir.src %>js/app/app.js'
# :
# : (省略)
# :
]
copy:
initStylus:
files: [
expand: true
cwd : '<%= dir.components %>bootstrap-stylus/stylus/'
src : ['*.styl']
dest : '<%= dir.src %>/stylus/bootstrap/'
filter: 'isFile'
]
initFont:
files: [
expand: true
cwd : '<%= dir.src %>fonts/icomoon/fonts/'
src : ['**']
dest : '<%= dir.dist %>css/fonts/'
filter: 'isFile'
,
expand: true
cwd : '<%= dir.src %>fonts/icomoon/fonts/'
src : ['**']
dest : '<%= dir.dist %>_dev/css/fonts/'
filter: 'isFile'
,
src : '<%= dir.src %>fonts/icomoon/style.css'
dest : '<%= dir.src %>/stylus/theme/modules/icomoon.styl'
]
initJs:
files: [
expand: true
cwd : '<%= dir.components %>jquery/'
src : ['jquery.js']
dest : '<%= dir.dist %>js/vendor/'
filter: 'isFile'
,
expand: true,
cwd : '<%= dir.components %>bootstrap-stylus/js/'
src : [
'affix.js'
'alert.js'
'button.js'
'carousel.js'
'collapse.js'
'dropdown.js'
#'modal.js' # use 'bootstrap-modal.js' -> jschr/bootstrap-modal · GitHub https://github.com/jschr/bootstrap-modal
'popover.js'
'scrollspy.js'
'tab.js'
'tooltip.js'
'transition.js'
]
dest : '<%= dir.src %>js/vendor/bootstrap/'
filter: 'isFile'
,
expand: true,
cwd : '<%= dir.components %>bootstrap-modal/js/'
src : [
'bootstrap-modal.js'
'bootstrap-modalmanager.js'
]
dest : '<%= dir.src %>js/vendor/bootstrap-modal/'
filter: 'isFile'
,
expand: true
cwd : '<%= dir.components %>modernizr/'
src : ['modernizr.js']
dest : '<%= dir.src %>js/vendor/'
filter: 'isFile'
,
expand: true
cwd : '<%= dir.components %>underscore/'
src : ['underscore.js']
dest : '<%= dir.src %>js/vendor/'
filter: 'isFile'
,
src : '<%= dir.components %>handlebars.runtime-v1.1.2.js/index.js'
dest : '<%= dir.src %>js/vendor/handlebars.runtime.js'
,
expand: true
cwd : '<%= dir.components %>backbone.marionette/lib/'
src : ['backbone.marionette.js']
dest : '<%= dir.src %>js/vendor/'
filter: 'isFile'
,
expand: true
cwd : '<%= dir.components %>backbone/'
src : ['backbone.js']
dest : '<%= dir.src %>js/vendor/'
filter: 'isFile'
,
expand: true
cwd : '<%= dir.components %>moment/'
src : ['moment.js']
dest : '<%= dir.src %>js/vendor/moment/'
filter: 'isFile'
,
expand: true
cwd : '<%= dir.components %>moment/lang/'
src : ['*.js']
dest : '<%= dir.dist %>js/vendor/moment/lang/'
filter: 'isFile'
,
expand: true
cwd : '<%= dir.components %>livestampjs/'
src : ['livestamp.js']
dest : '<%= dir.src %>js/vendor/'
filter: 'isFile'
,
expand: true
cwd : '<%= dir.components %>spinjs/dist'
src : ['spin.js']
dest : '<%= dir.src %>js/vendor/'
filter: 'isFile'
,
expand: true
cwd : '<%= dir.components %>spinjs/'
src : ['jquery.spin.js']
dest : '<%= dir.src %>js/vendor/'
filter: 'isFile'
,
expand: true
cwd : '<%= dir.components %>jquery.transit/'
src : ['jquery.transit.js']
dest : '<%= dir.src %>js/vendor/'
filter: 'isFile'
,
expand: true
cwd : '<%= dir.components %>perfect-scrollbar/src/'
src : [
'jquery.mousewheel.js'
'perfect-scrollbar.js'
]
dest : '<%= dir.src %>js/vendor/'
filter: 'isFile'
]
js:
files: [
expand: true
cwd : '<%= dir.src %>tmp/'
src : ['main.min.map']
dest : '<%= dir.dist %>js/'
filter: 'isFile'
,
expand: true
cwd : '<%= dir.src %>_dev/js/'
src : ['backbone.debug.js']
dest : '<%= dir.dist %>/_dev/js/'
filter: 'isFile'
,
expand: true
cwd : '<%= dir.src %>_dev/js/'
src : ['api-mock.js']
dest : '<%= dir.dist %>/_dev/js/'
filter: 'isFile'
]
stylus: # https://github.com/gruntjs/grunt-contrib-stylus
prod:
files :
'<%= dir.src %>css/bootstrap.css': '<%= dir.src %>stylus/bootstrap/bootstrap-mod.styl'
'<%= dir.src %>css/theme.css': '<%= dir.src %>stylus/theme/import.styl'
'<%= dir.dist %>_dev/css/bootstrap.css': '<%= dir.src %>stylus/bootstrap/bootstrap-mod.styl'
'<%= dir.dist %>_dev/css/theme.css': '<%= dir.src %>stylus/theme/import.styl'
dev:
options:
firebug: true
files :
'<%= dir.src %>css/bootstrap.css': '<%= dir.src %>stylus/bootstrap/bootstrap-mod.styl'
'<%= dir.src %>css/theme.css': '<%= dir.src %>stylus/theme/import.styl'
'<%= dir.dist %>_dev/css/bootstrap.css': '<%= dir.src %>stylus/bootstrap/bootstrap-mod.styl'
'<%= dir.dist %>_dev/css/theme.css': '<%= dir.src %>stylus/theme/import.styl'
cssmin:
compress:
files:
'<%= dir.src %>tmp/main.min.css': [
'<%= dir.src %>css/bootstrap.css'
'<%= dir.src %>css/theme.css'
]
handlebars: # https://github.com/gruntjs/grunt-contrib-handlebars
compile:
options:
namespace: 'App.jst'
processName: (filepath) -> # input -> app/hbs/partial.hbs
pieces = filepath.split('/')
return pieces[pieces.length - 1].replace(/.hbs$/ , '') # output -> partial
files:
'<%= dir.src %>js/app/templates.js': '<%= dir.src %>js/app/hbs/*.hbs'
uglify: # https://github.com/gruntjs/grunt-contrib-uglify
prod:
options:
mangle: true
compress: true
files :
'<%= dir.src %>tmp/main.min.js': '<%= uglifyFiles %>'
dev:
options:
mangle: false
compress: false
beautify:
width: 120
beautify: true
sourceMap : (path) ->
path.replace /\.js$/, '.map'
sourceMapRoot: '/resources/'
sourceMappingURL: (path) ->
'./' + path.replace /.+\/(.+?)\.js$/, '$1.map'
files :
'<%= dir.src %>tmp/main.min.js': '<%= uglifyFiles %>'
modernizr:
files :
'<%= dir.dist %>js/vendor/modernizr.min.js': '<%= dir.src %>js/vendor/modernizr.js'
concat: # https://github.com/gruntjs/grunt-contrib-concat
js:
src: [
'<%= dir.src %>js/_licenses.js'
'<%= dir.src %>tmp/main.min.js'
]
dest: '<%= dir.dist %>js/main.min.js'
css:
src: [
'<%= dir.src %>css/_licenses.css'
'<%= dir.src %>tmp/main.min.css'
]
dest: '<%= dir.dist %>css/main.min.css'
clean:
tmp:
src: [
'<%= dir.src %>tmp/*'
]
compress: # https://github.com/gruntjs/grunt-contrib-compress
css:
options:
mode: 'gzip'
files : [
expand: true
cwd : '<%= dir.dist %>css/'
src : ['main.min.css']
dest : '<%= dir.dist %>css/'
ext : '.min.css.gz'
]
js:
options:
mode: 'gzip'
files : [
expand: true
cwd : '<%= dir.dist %>js/'
src : ['main.min.js']
dest : '<%= dir.dist %>js/'
ext : '.min.js.gz'
]
esteWatch:
options:
# just a dirs, no file paths
dirs : [
'<%= dir.src %>_dev/**/'
'<%= dir.src %>js/**/'
'<%= dir.src %>stylus/**/'
'!<%= dir.src %>tmp/**/'
]
livereload:
enabled : true
port : 35729
extensions: ['js', 'css', 'gz', 'json', 'styl']
hbs: (filepath) ->
return [
'handlebars'
'uglify:' + target
'concat:js'
'copy:js'
'clean'
'compress:js'
'notify:esteWatch'
]
js: (filepath) ->
return [
'uglify:' + target
'concat:js'
'copy:js'
'clean'
'compress:js'
'notify:esteWatch'
]
styl: (filepath) ->
return [
'stylus:' + target
'cssmin'
'concat:css'
'clean'
'compress:css'
'notify:esteWatch'
]
notify:
esteWatch:
options:
message: 'Grunt Task [esteWatch] Complete'
grunt.loadNpmTasks 'grunt-contrib'
grunt.loadNpmTasks 'grunt-este-watch'
grunt.loadNpmTasks 'grunt-notify'
grunt.registerTask 'default', 'esteWatch'
grunt.event.on 'esteWatch', (action, filepath) ->
grunt.config ['jshint', 'all'], [filepath]
grunt.log.write action
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment