Created
January 9, 2014 00:22
-
-
Save willmendesneto/8327283 to your computer and use it in GitHub Desktop.
Gruntfile template for use in projects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generated on 2013-10-07 using generator-angular 0.4.0 | |
// | |
// OBS: | |
// Replace the string with informations | |
// '<%= yeomanConfig.assets.css %>' = Stylesheets folder | |
// '<%= yeomanConfig.assets.js %>' = Scripts folder | |
// '<%= yeomanConfig.assets.img %>' = Images folder | |
// '<%= yeomanConfig.assets.font %>' = Fonts folder | |
// | |
'use strict'; | |
var LIVERELOAD_PORT = 35730; | |
var lrSnippet = require('connect-livereload')({ port: LIVERELOAD_PORT }); | |
var mountFolder = function (connect, dir) { | |
return connect.static(require('path').resolve(dir)); | |
}; | |
// # Globbing | |
// for performance reasons we're only matching one level down: | |
// 'test/spec/{,*/}*.js' | |
// use this if you want to recursively match all subfolders: | |
// 'test/spec/**/*.js' | |
module.exports = function (grunt) { | |
require('load-grunt-tasks')(grunt); | |
require('time-grunt')(grunt); | |
// configurable paths | |
var yeomanConfig = { | |
app: 'app', | |
dist: 'dist' | |
}; | |
// global folders settings | |
// in "app" and "dist" folders | |
try { | |
yeomanConfig.app = yeomanConfig.app; | |
} catch (e) {} | |
grunt.initConfig({ | |
yeoman: yeomanConfig, | |
watch: { | |
styles: { | |
files: ['<%= yeoman.app %>/<%= yeomanConfig.assets.css %>/{,*/}*.css'], | |
tasks: ['copy:styles', 'autoprefixer'] | |
}, | |
livereload: { | |
options: { | |
livereload: LIVERELOAD_PORT | |
}, | |
files: [ | |
'{.tmp,<%= yeoman.app %>}/<%= yeomanConfig.assets.css %>/{,*/}*.css', | |
'{.tmp,<%= yeoman.app %>}/{,*/}*.html', | |
'{.tmp,<%= yeoman.app %>}/<%= yeomanConfig.assets.js %>/{,*/}*.js', | |
'{.tmp,<%= yeoman.app %>}/<%= yeomanConfig.assets.img %>/{,*/}*.{png,jpg,jpeg,gif,webp,svg}' | |
] | |
} | |
}, | |
autoprefixer: { | |
options: ['last 1 version'], | |
dist: { | |
files: [{ | |
expand: true, | |
cwd: '.tmp/<%= yeomanConfig.assets.css %>/', | |
src: '{,*/}*.css', | |
dest: '.tmp/<%= yeomanConfig.assets.css %>/' | |
}] | |
} | |
}, | |
connect: { | |
options: { | |
port: 9100, | |
// Change this to '0.0.0.0' to access the server from outside. | |
hostname: 'localhost' | |
}, | |
livereload: { | |
options: { | |
middleware: function (connect) { | |
return [ | |
lrSnippet, | |
mountFolder(connect, '.tmp'), | |
mountFolder(connect, yeomanConfig.app) | |
]; | |
} | |
} | |
}, | |
dist: { | |
options: { | |
middleware: function (connect) { | |
return [ | |
mountFolder(connect, yeomanConfig.dist) | |
]; | |
} | |
} | |
} | |
}, | |
open: { | |
server: { | |
url: 'http://localhost:<%= connect.options.port %>' | |
} | |
}, | |
clean: { | |
dist: { | |
files: [{ | |
dot: true, | |
src: [ | |
'.tmp', | |
'<%= yeoman.dist %>/*', | |
'!<%= yeoman.dist %>/.git*' | |
] | |
}] | |
}, | |
server: '.tmp' | |
}, | |
jshint: { | |
options: { | |
jshintrc: '.jshintrc', | |
ignores: [ | |
'Gruntfile.js' | |
] | |
}, | |
all: [ | |
'Gruntfile.js', | |
'<%= yeoman.app %>/<%= yeomanConfig.assets.js %>/{,*/}*.js' | |
] | |
}, | |
// not used since Uglify task does concat, | |
// but still available if needed | |
concat: { | |
dist: { | |
files: { | |
src: [ | |
'<%= yeoman.dist %>/<%= yeomanConfig.assets.js %>/{,*/}*.js', | |
'<%= yeoman.dist %>/<%= yeomanConfig.assets.css %>/{,*/}*.css', | |
'<%= yeoman.dist %>/<%= yeomanConfig.assets.img %>/{,*/}*.{png,jpg,jpeg,gif,webp,svg}', | |
'<%= yeoman.dist %>/<%= yeomanConfig.assets.font %>/*' | |
] | |
} | |
} | |
}, | |
rev: { | |
dist: { | |
files: { | |
src: [ | |
'<%= yeoman.dist %>/<%= yeomanConfig.assets.js %>/{,*/}*.js', | |
'<%= yeoman.dist %>/<%= yeomanConfig.assets.css %>/{,*/}*.css', | |
'<%= yeoman.dist %>/<%= yeomanConfig.assets.img %>/{,*/}*.{png,jpg,jpeg,gif,webp,svg}', | |
'<%= yeoman.dist %>/<%= yeomanConfig.assets.font %>/*' | |
] | |
} | |
} | |
}, | |
useminPrepare: { | |
html: '<%= yeoman.app %>/index.html', | |
options: { | |
dest: '<%= yeoman.dist %>' | |
} | |
}, | |
usemin: { | |
html: ['<%= yeoman.dist %>/{,*/}*.html'], | |
css: ['<%= yeoman.dist %>/<%= yeomanConfig.assets.css %>/{,*/}*.css'], | |
options: { | |
dirs: ['<%= yeoman.dist %>'] | |
} | |
}, | |
imagemin: { | |
dist: { | |
files: [{ | |
expand: true, | |
cwd: '<%= yeoman.app %>/<%= yeomanConfig.assets.img %>', | |
src: '{,*/}*.{png,jpg,jpeg}', | |
dest: '<%= yeoman.dist %>/<%= yeomanConfig.assets.img %>' | |
}] | |
} | |
}, | |
svgmin: { | |
dist: { | |
files: [{ | |
expand: true, | |
cwd: '<%= yeoman.app %>/<%= yeomanConfig.assets.img %>', | |
src: '{,*/}*.svg', | |
dest: '<%= yeoman.dist %>/<%= yeomanConfig.assets.img %>' | |
}] | |
} | |
}, | |
cssmin: { | |
// By default, your `index.html` <!-- Usemin Block --> will take care of | |
// minification. This option is pre-configured if you do not wish to use | |
// Usemin blocks. | |
dist: { | |
files: { | |
'<%= yeoman.dist %>/<%= yeomanConfig.assets.css %>/main.min.css': [ | |
'.tmp/<%= yeomanConfig.assets.css %>/{,*/}*.css', | |
'<%= yeoman.app %>/<%= yeomanConfig.assets.css %>/{,*/}*.css' | |
] | |
} | |
} | |
}, | |
htmlmin: { | |
dist: { | |
options: { | |
/*removeCommentsFromCDATA: true, | |
// https://github.com/yeoman/grunt-usemin/issues/44 | |
//collapseWhitespace: true, | |
collapseBooleanAttributes: true, | |
removeAttributeQuotes: true, | |
removeRedundantAttributes: true, | |
useShortDoctype: true, | |
removeEmptyAttributes: true, | |
removeOptionalTags: true*/ | |
}, | |
files: [{ | |
expand: true, | |
cwd: '<%= yeoman.app %>', | |
src: ['*.html'], | |
dest: '<%= yeoman.dist %>' | |
}] | |
} | |
}, | |
bower: { | |
install: { | |
verbose: true, | |
} | |
}, | |
// Put files not handled in other tasks here | |
copy: { | |
dist: { | |
files: [{ | |
expand: true, | |
dot: true, | |
cwd: '<%= yeoman.app %>', | |
dest: '<%= yeoman.dist %>', | |
src: [ | |
'*.{ico,php,png,txt}', | |
'.htaccess', | |
'<%= yeomanConfig.assets.img %>/{,*/}*.{gif,webp}', | |
'<%= yeomanConfig.assets.font %>/*' | |
] | |
}, { | |
expand: true, | |
cwd: '.tmp/<%= yeomanConfig.assets.img %>', | |
dest: '<%= yeoman.dist %>/<%= yeomanConfig.assets.img %>', | |
src: [ | |
'generated/*' | |
] | |
}] | |
}, | |
styles: { | |
expand: true, | |
cwd: '<%= yeoman.app %>/<%= yeomanConfig.assets.css %>', | |
dest: '.tmp/<%= yeomanConfig.assets.css %>/', | |
src: '{,*/}*.css' | |
} | |
}, | |
concurrent: { | |
server: [ | |
'copy:styles' | |
], | |
dist: [ | |
'copy:styles', | |
'imagemin', | |
'svgmin', | |
'htmlmin' | |
] | |
}, | |
cdnify: { | |
dist: { | |
html: ['<%= yeoman.dist %>/*.html'] | |
} | |
}, | |
uglify: { | |
dist: { | |
files: { | |
'<%= yeoman.dist %>/<%= yeomanConfig.assets.js %>/scripts.js': [ | |
'<%= yeoman.dist %>/<%= yeomanConfig.assets.js %>/scripts.js' | |
] | |
} | |
} | |
}, | |
htmllint: { | |
dist: ['<%= yeoman.dist %>/*.html'] | |
}, | |
rsync: { | |
options: { | |
args: ["--verbose"], | |
exclude: [".git*","*.scss","node_modules"], | |
recursive: true | |
}, | |
prod: { | |
options: { | |
src: '<%= yeoman.dist %>/', | |
dest: "/path/to/your/website/destiny/", | |
host: "yourhost@websiteaddress", | |
syncDestIgnoreExcl: true | |
} | |
} | |
} | |
}); | |
grunt.loadNpmTasks('grunt-html'); | |
grunt.loadNpmTasks('grunt-rsync'); | |
grunt.registerTask('server', function (target) { | |
if (target === 'dist') { | |
return grunt.task.run(['build', 'open', 'connect:dist:keepalive']); | |
} | |
grunt.task.run([ | |
'clean:server', | |
'concurrent:server', | |
'autoprefixer', | |
'connect:livereload', | |
'open', | |
'watch' | |
]); | |
}); | |
grunt.registerTask('build', [ | |
'jshint', | |
'htmllint', | |
'clean:dist', | |
'useminPrepare', | |
'concurrent:dist', | |
'autoprefixer', | |
'concat', | |
//'cdnify', | |
'cssmin', | |
'uglify', | |
'copy:dist', | |
'rev', | |
'usemin' | |
]); | |
grunt.registerTask('deploy', [ | |
'rsync:prod' | |
]); | |
grunt.registerTask('travis', [ | |
'bower:install', | |
'jshint', | |
'build', | |
'htmllint' | |
]); | |
grunt.registerTask('default', [ | |
'jshint', | |
'build' | |
]); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment