Last active
December 19, 2015 08:59
-
-
Save candidosales/5930064 to your computer and use it in GitHub Desktop.
Cria uma pasta dist, onde conterá todos os arquivos essenciais para produção. 1. Limpar dist;
2. Compila LESS;
3.1 Ler o index.html onde encontrar a posição e ordem dos CSS e JS, já configurando-os para concatenar e minificar;
4. Comprimir imagens e jogar na pasta dist;
5. Concatenar css, js;
6. Minificar css concatenado e jogar na pasta dist;
7…
This file contains 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
/*global module:false*/ | |
module.exports = function(grunt) { | |
// load all grunt tasks | |
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks); | |
// Project configuration. | |
grunt.initConfig({ | |
// Metadata. | |
pkg: grunt.file.readJSON('package.json'), | |
banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' + | |
'<%= grunt.template.today("yyyy-mm-dd") %>\n' + | |
'<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' + | |
'* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %> - <%= pkg.author.email %> - <%= pkg.author.twitter%>;' + | |
' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n', | |
// Task configuration. | |
dir: { | |
app: 'app', | |
dist: 'dist' | |
}, | |
clean: { | |
dist: { | |
files: [{ | |
dot: true, | |
src: [ | |
'<%= dir.dist %>/*' | |
] | |
}] | |
} | |
}, | |
less: { | |
development: { | |
files: { | |
"<%= dir.app %>/css/app.css": "<%= dir.app %>/css/app.less" | |
} | |
}, | |
production: { | |
options: { | |
yuicompress: true | |
}, | |
files: { | |
"<%= dir.app %>/css/app.css": "<%= dir.app %>/css/app.less" | |
} | |
} | |
}, | |
useminPrepare: { | |
html: '<%= dir.app %>/index.html', | |
options: { | |
dest: '<%= dir.dist %>' | |
} | |
}, | |
usemin: { | |
html: ['<%= dir.dist %>/{,*/}*.html'], | |
css: ['<%= dir.dist %>/css/{,*/}*.css'], | |
options: { | |
dirs: ['<%= dir.dist %>'] | |
} | |
}, | |
imagemin: { | |
dist: { | |
options: { // Target options | |
optimizationLevel: 3 | |
}, | |
files: [{ | |
expand: true, | |
cwd: '<%= dir.app %>/img', | |
src: '{,*/}*.{png,jpg,jpeg}', | |
dest: '<%= dir.dist %>/img' | |
}] | |
} | |
}, | |
htmlmin: { | |
dist: { | |
options: { | |
removeComments: true, | |
useShortDoctype: true, | |
collapseWhitespace: true, | |
removeEmptyAttributes: true, | |
removeCDATASectionsFromCDATA: true | |
}, | |
files: [{ | |
expand: true, | |
cwd: '<%= dir.dist %>', | |
src: ['*.html'], | |
dest: '<%= dir.dist %>' | |
}] | |
} | |
}, | |
copy: { | |
dist: { | |
files: [{ | |
expand: true, | |
dot: true, | |
cwd: '<%= dir.app %>', | |
dest: '<%= dir.dist %>', | |
src: [ | |
'*.html', | |
'*.{ico,txt}', | |
'.htaccess', | |
//'components/**/*', | |
'img/{,*/}*.{gif,webp}', | |
'css/fonts/*' | |
] | |
}] | |
} | |
}, | |
}); | |
// Default task. | |
grunt.registerTask('build', [ | |
'clean:dist', | |
'less:production', | |
'useminPrepare', | |
'imagemin', | |
'concat', | |
'cssmin', | |
'copy', | |
'uglify', | |
'usemin', | |
'htmlmin' | |
]); | |
grunt.registerTask('default', ['build']); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment