Skip to content

Instantly share code, notes, and snippets.

@fdaciuk
Last active December 15, 2015 13:19
Show Gist options
  • Save fdaciuk/5266715 to your computer and use it in GitHub Desktop.
Save fdaciuk/5266715 to your computer and use it in GitHub Desktop.
Gruntfile.js padrão para projetos em WP.
{
"curly": true,
"eqeqeq": true,
"immed": true,
"latedef": true,
"newcap": true,
"noarg": true,
"sub": true,
"undef": true,
"boss": true,
"eqnull": true,
"node": true,
"globals" : {
"console" : true,
"document" : true,
"window" : true,
"jQuery" : true,
"Socialite" : true
}
}
module.exports = function( grunt ) {
'use strict';
grunt.initConfig({
// Ler o arquivo package.json, para pegar informações do projeto
pkg : grunt.file.readJSON( 'package.json' ),
// Nome do diretório do tema do WP
theme_name : 'theme_name',
// Diretório padrão dos assets (CSS, JS e imagens)
assets_src_path : '../site/themes/<%= theme_name %>/assets',
// Diretórios de src e build dos arquivos SASS (CSS) e JS
css_src_path : '<%= assets_src_path %>/_sass',
css_build_path : '<%= assets_src_path %>/css',
js_src_path : '<%= assets_src_path %>/_js',
js_build_path : '<%= assets_src_path %>/js',
img_src_path : '<%= assets_src_path %>/images',
img_build_path : '<%= assets_src_path %>/img',
// Tarefas do Grunt
concat : {
options : { separator : ';\n' },
head_scripts : {
src : [
'<%= js_src_path %>/lib/modernizr.js',
// '<%= js_src_path %>/lib/typekit.js'
],
dest : '<%= js_build_path %>/head-scripts.js'
},
js : {
src : [
// Todos os arquivos de /lib, na ordem abaixo
'<%= js_src_path %>/lib/jquery.js',
'<%= js_src_path %>/lib/jquery.plugins.js',
'<%= js_src_path %>/lib/socialite.min.js',
// O script principal, que conterá as funções para todas as páginas
'<%= js_src_path %>/scripts.js',
// Os scripts que serão usados para páginas específicas
'<%= js_src_path %>/app/*.js'
],
// Arquivo JS que será compilado
dest : '<%= js_build_path %>/main.js'
}
}, // concat
uglify : {
options : {
mangle : true
},
// Minifica o arquivo JS gerado pelo concat
js : {
files : {
'<%= concat.head_scripts.dest %>' : '<%= concat.head_scripts.dest %>',
'<%= concat.js.dest %>' : '<%= concat.js.dest %>'
}
}
}, // uglify
jshint : {
options : {
jshintrc : '../.jshintrc'
},
all : [ 'Gruntfile.js', '<%= js_src_path %>/scripts.js', '<%= js_src_path %>/app/*.js' ]
},
compass : {
options : {
sassDir : '<%= css_src_path %>',
cssDir : '<%= css_build_path %>',
imagesDir : '<%= img_src_path %>'
},
dev : {
options : {
outputStyle : 'expanded'
}
},
dist : {
options : {
outputStyle : 'compressed'
}
}
}, // compass
smushit : {
path : {
src : '<%= img_src_path %>/**/*'
}
}, // smushit
watch : {
// Asssiste todos os arquivos
dist : {
files : [
'<%= js_src_path %>/**/*.js',
'<%= css_src_path %>/*'
],
tasks : [ 'compass:dev', 'jshint', 'concat', 'notify:notify_default' ]
},
// Asssiste só os arquivos JS
wjs : {
files : [ '<%= js_src_path %>/**/*' ],
tasks : [ 'jshint', 'concat', 'notify:wjs' ]
},
// Asssiste só os arquivos CSS
wcss : {
files : [ '<%= css_src_path %>/**/*' ],
tasks : [ 'compass:dev', 'notify:wcss' ]
}
}, // watch
// Notificações
notify : {
notify_default : {
options : {
title : '<%= pkg.title %>',
message : 'Compilação finalizada!'
}
},
wcss : {
options : {
title : 'SASS - <%= pkg.title %>',
message : 'Compilado e minificado!'
}
},
wjs : {
options : {
title : 'Javascript - <%= pkg.title %>',
message : 'JS Pronto!'
}
},
img : {
options : {
title : '<%= pkg.title %>',
message : 'Imagens minificadas!'
}
}
},
// rsync
rsync : {
options : {
args : [ '--verbose' ],
exclude : [
'.git*',
'**.DS_Store',
'**__MACOSX',
'src',
'wp-config.php',
'.htaccess'
],
recursive : true,
compareMode: "checksum"
},
stage : {
options : {
src : '../',
dest : '/path/on/server',
host : 'username@host.com',
syncDestIgnoreExcl: true
}
},
prod : {
options : {}
}
}
});
// Plugins Grunt
require( 'load-grunt-tasks' )( grunt );
// Tarefa Default
grunt.registerTask( 'default', [ 'compass:dist', 'concat', 'uglify', 'jshint', 'notify:notify_default' ] );
// Tarefas para watch
grunt.registerTask( 'w', [ 'watch:dist' ] );
grunt.registerTask( 'wjs', [ 'watch:wjs' ] );
grunt.registerTask( 'wcss', [ 'watch:wcss' ] );
// Tarefa para minificação de imagens
grunt.registerTask( 'img', [ 'smushit', 'notify:img' ] );
// Deploy Servidor de homologação (stage)
grunt.registerTask( 's', [ 'rsync:stage' ] );
// Deploy Servidor de produção
grunt.registerTask( 'dpl', [ 'rsync:prod' ] );
};
{
"name": "project_name",
"version": "1.0.0",
"title": "Project Title",
"homepage": "http://www.site.com.br",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-uglify": "~0.2.2",
"grunt-contrib-watch": "~0.4.4",
"grunt-notify": "~0.2.4",
"grunt-smushit": "~1.0.1",
"grunt-contrib-compass": "~0.2.0",
"grunt-contrib-jshint": "~0.6.0",
"grunt-rsync": "~0.2.0",
"load-grunt-tasks": "~0.1.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment