Skip to content

Instantly share code, notes, and snippets.

@octavioamu
Created January 11, 2014 16:43
Show Gist options
  • Save octavioamu/8373278 to your computer and use it in GitHub Desktop.
Save octavioamu/8373278 to your computer and use it in GitHub Desktop.
Grunt configuration w/ commands execs
/*!
* Project Gruntfile
*/
'use strict';
module.exports = function( grunt ) {
// Dynamically load npm tasks
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
var appConfig = {
dirs: {
js: "../javascripts",
less: "../stylesheets/less",
css: "../stylesheets",
img: "../images"
},
// Metadata
pkg: grunt.file.readJSON("package.json"),
banner :'/* \n '+
'* Project: <%= pkg.name %> - version <%= pkg.version %> \n '+
'* Description: <%= pkg.description %> \n '+
'* Repository: <%= pkg.repository %> \n '+
'* Author: <%= pkg.author.name %> \n '+
'* Github: <%= pkg.author.github %> \n '+
'* Start in: <%= pkg.startin %> \n '+
'* Last Update: <%= grunt.template.today("dd/mm/yyyy") %> \n '+
'*/ \n',
// Projects variables
// Config task here
// Watch task
watch: {
options: {
livereload: true
},
js: {
files: [
"<%= dirs.js %>/**/*.js"
],
tasks: ["uglify", "jshint"]
},
less: {
files: [
'<%= dirs.less %>/**/*.less',
'<%= dirs.less %>/*.less'
],
tasks: "less"
},
html: {
files: "../../*.html"
}
},
// Less compile task
less: {
dev: {
files: {
'<%= dirs.css %>/style.min.css.erb': '<%= dirs.less %>/imports.less'
},
options: {
//yuicompress: true
}
},
dist: {
files: {
'<%= dirs.css %>/style.min.css.erb': '<%= dirs.less %>/imports.less'
},
options: {
//yuicompress: true
}
}
},
// CSSO Minification task
csso: {
dev: {
options: {
banner: '<%= banner %>'
},
files: {
'<%= dirs.css %>/style.min.css.erb': [
'<%= dirs.css %>/style.css'
]
}
},
dist: {
options: {
banner: '<%= banner %>'
},
files: {
'<%= dirs.css %>/style.min.css.erb': [
'<%= dirs.css %>/style.css'
]
}
}
},
// livereload task
connect: {
server: {
options: {
port: 9000,
base: ".",
hostname: "localhost",
livereload: true,
open: true
}
}
},
// jshint task
jshint: {
options: {
globals: {
jQuery: true,
console: true,
module: true
},
bitwise: true,
expr: true
}
},
// uglify task
uglify: {
options: {
banner: "<%= banner %>",
mangle: false
},
dist: {
files: {
"<%= dirs.js %>/site.min.js": [
"<%= dirs.js %>/plugins/*.js",
"<%= dirs.js %>/custom/*.js"
]
// ],
// "<%= dirs.js %>/plugins.min.js": [
// "<%= dirs.js %>/plugins/*.js"
// ]
}
}
}
};
grunt.initConfig(appConfig);
// Load plugins
// grunt.loadNpmTasks('grunt-contrib-concat');
// grunt.loadNpmTasks('grunt-contrib-less');
// grunt.loadNpmTasks('grunt-contrib-uglify');
// grunt.loadNpmTasks('grunt-contrib-jshint');
// grunt.loadNpmTasks('grunt-contrib-connect');
// grunt.loadNpmTasks('grunt-csso');
// grunt.loadNpmTasks('grunt-contrib-clean');
// grunt.loadNpmTasks('grunt-contrib-watch');
// grunt.loadNpmTasks('grunt-notify');
// Register custom task
//grunt.registerTask( "default", [ "connect", "watch" ]);
// grunt.registerTask( 'dev', [ 'tarefa' ] );
// grunt.registerTask( 'build', [ 'tarefa' ] );
// grunt.registerTask( 'front', ['less', 'jshint', 'uglify', 'watch', 'connect','notify']);
// grunt.registerTask( 'default', ['less', 'jshint', 'uglify', 'watch', 'connect','notify']);
/**
* Default task
* Run `grunt` on the command line
*/
grunt.registerTask('default', [
'less:dev',
'csso:dev',
'jshint',
'watch',
'connect',
'notify'
]);
/**
* Build task
* Run `grunt build` on the command line
* Then compress all JS/CSS files
*/
grunt.registerTask('build', [
'less:dist',
'csso:dist',
'jshint',
'uglify',
'notify'
]);
/**
* Front task
* Run `grunt build` on the command line
* Then compress all JS/CSS files
*/
grunt.registerTask('front', [
'less:dist',
'csso:dist',
'jshint',
'uglify',
'jshint',
'watch',
'connect',
'notify'
]);
};
@echo off
IF not exist node_modules (npm install)
grunt build
cd "$(dirname "$0")"
if [ ! -d node_modules ];then
sudo npm install
fi
grunt build
{
"watch": {
"options": {
"livereload": true
},
"css": {
"files": "sass/{,*/}*.{scss,sass}",
"tasks": "compass"
},
"js": {
"files": "<%= jshint.all %>",
"tasks": ["jshint", "uglify"]
},
"html": {
"files": [ "/*.{html,htm,shtml,shtm,xhtml,php,jsp,asp,aspx,erb,ctp}" ]
}
},
"connect": {
"server": {
"options": {
"port": 9000,
"base": ".",
"hostname": "localhost",
"livereload": true,
"open": true
}
}
},
"jshint": {
"options": {
"jshintrc": ".jshintrc"
},
"all": [ "Gruntfile.js", "js/main.js" ]
},
"uglify": {
"options": {
"mangle": false
},
"dist": {
"files": {
"js/main.min.js": [
"js/main.js"
],
"js/plugins.min.js": [
"js/plugins.js"
]
}
}
},
"compass": {
"dist": {
"options": {
"force": true,
"config": "config.rb"
}
}
}
}
@echo off
IF not exist node_modules (npm install)
grunt
cd "$(dirname "$0")"
if [ ! -d node_modules ];then
sudo npm install
fi
grunt
{
"name": "project-name",
"version": "1.0.0",
"description": "Project description",
"repository": "https://github.com/reponame",
"author": {
"name": "Name",
"github": "https://github.com/name"
},
"startin": "00/00/2013",
"devDependencies": {
"grunt": "~0.4.2",
"load-grunt-tasks": "~0.2.0",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-less": ">= 0.8.0",
"grunt-contrib-uglify": ">= 0.2.0",
"grunt-contrib-jshint": ">= 0.6.4",
"grunt-contrib-connect": ">= 0.3.0",
"grunt-csso": ">= 0.5.0",
"grunt-contrib-clean": ">= 0.5.0",
"connect-livereload": ">= 0.2.0",
"grunt-contrib-watch": ">= 0.5.3",
"grunt-notify": ">= 0.2.13",
"matchdep": "~0.1.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment