Skip to content

Instantly share code, notes, and snippets.

@tonybolanyo
Last active December 15, 2015 14:22
Show Gist options
  • Save tonybolanyo/26d6f7d65b7d5ad4d3ab to your computer and use it in GitHub Desktop.
Save tonybolanyo/26d6f7d65b7d5ad4d3ab to your computer and use it in GitHub Desktop.
[blog.tonygb.com] Gruntfile para mis temas web
module.exports = function(grunt) {
var cleanCssOptions = {
advanced: true
}
// configura las tareas
grunt.initConfig({
clean: {
build: {
src: [ 'dist' ]
},
stylesheets: {
src: [ 'dist/**/*.css', '!dist/css/application.css' ]
},
scripts: {
src: [ 'dist/**/*.js', '!dist/application.js' ]
},
},
coffee: {
build: {
expand: true,
cwd: 'src',
src: [ '**/*.coffee' ],
dest: 'dist',
ext: '.js'
}
},
connect: {
server: {
options: {
port: 3000,
base: 'dist',
hostname: '*'
}
}
},
copy: {
build: {
cwd: 'src',
src: [ '**', '!**/*.less', '!**/*.coffee' ],
dest: 'dist',
expand: true
},
},
cssmin: {
build: {
files: {
'dist/css/application.css': [ 'dist/**/*.css' ]
}
}
},
less: {
dev: {
options: {
paths: ["assets/css"]
},
files: {
"dist/css/styles.css": "src/css/styles.less"
}
},
prod: {
options: {
plugins: [
new (require('less-plugin-autoprefix'))({browsers: ["last 2 versions"]}),
new (require('less-plugin-clean-css'))(cleanCssOptions)
]
},
files: {
"dist/css/styles.css": "src/css/styles.less"
}
}
},
uglify: {
build: {
options: {
mangle: false
},
files: {
'dist/js/application.js': [ 'src/**/*.js' ]
}
}
},
watch: {
copy: {
files: [ 'src/**' ],
tasks: [ 'copy' ]
}
},
});
// carga las tareas
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-coffee');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
// define los comandos para las tareas
grunt.registerTask(
'build',
'Copia todos los archivos fuente al directorio de distribución y compila las hojas de estilo con less.',
[ 'clean:build', 'copy', 'stylesheets', 'scripts' ]
);
grunt.registerTask(
'scripts',
'Compila los archivos JavaScript.',
[ 'coffee', 'uglify', 'clean:scripts' ]
);
grunt.registerTask(
'stylesheets',
'Compila las hojas de estilo.',
[ 'less:prod', 'cssmin', 'clean:stylesheets' ]
);
grunt.registerTask(
'default',
'Vigila los cambios en el proyecto y automáticamente copia los archivos y lanza el servidor de prueba.',
[ 'clean', 'copy', 'less:dev', 'scripts', 'connect', 'watch' ]
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment