// GRUNT PROCESS
npm init
npm install grunt --save-dev
// Create Gruntfile.js
npm install grunt-contrib-watch --save-dev
// npm install grunt-browser-sync // I don't like it
npm install grunt-contrib-sass --save-dev
npm install grunt-contrib-copy --save-dev
npm install --save-dev grunt-cwebp
// Es posible que existan vulnerabilidades
npm audit fix
Ejemplo de Gruntfile.js
//Gruntfile.js
module.exports = function (grunt) {
grunt.initConfig({
// Watch task config con Sass
watch: {
options: {
nospawn: true,
livereload: true
},
sass: {
files: ['src/assets/css/**/*.scss'],
tasks: ['sass']
},
copy: {
files: ['src/**'],
tasks: ['copy:main']
}
},
// COPY task congif
copy: {
main: {
expand: true,
cwd: 'src/',
src: ["**/*", "!css/**/*.scss"],
dest: 'dist/'
}
},
// Sass task config
sass: {
dist: {
options: {
style: 'compressed',
noCache: true
},
files: [{
expand: true,
cwd: "src/assets/css",
src: ["*.scss"],
dest: "src/assets/css",
ext: ".css"
}]
}
},
cwebp: {
// static: {
// files: {
// 'dist/img-png.webp': 'src/img.png',
// 'dist/img-jpg.webp': 'src/img.jpg',
// 'dist/img-gif.webp': 'src/img.gif'
// }
// },
dynamic: {
options: {
// SET QUALITY OF EXPORTED WEBP (0 - 100)
q: 50
},
files: [{
expand: true,
cwd: 'src/',
src: ['**/*.{png,jpg,gif}'],
dest: 'dist/'
}]
}
}
});
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-cwebp');
//Tarea por defecto
grunt.registerTask('default', ['copy', 'cwebp', 'watch']);
};