|
|
|
|
|
/* FORK: http://aaronlasseigne.com/2016/02/03/using-gulp-with-jekyll/ */ |
|
|
|
/* TAREA SASS https://gist.github.com/BCasal/1eb6747760abe62472aa */ |
|
|
|
// DEPENDENCIAS |
|
|
|
const child = require('child_process'); |
|
const browserSync = require('browser-sync').create(); |
|
const gulp = require('gulp'); |
|
const gutil = require('gulp-util'); |
|
const sass = require('gulp-sass'); |
|
const autoprefixer = require('gulp-autoprefixer'); |
|
const rename = require('gulp-rename'); |
|
|
|
// RUTAS |
|
|
|
const siteRoot = '_site'; |
|
const sassSrc = '_sass/style.scss'; |
|
const sassDest = 'assets/css/'; |
|
|
|
|
|
|
|
// TAREA SASS |
|
|
|
// * 1 * // archivo de origen (archivo con imports) |
|
// * 2 * // compresión desarrollo (legible) |
|
// * 3 * // auto-prefijos (más info https://github.com/ai/browserslist) |
|
// * 4 * // destino producción |
|
// * 5 * // copia y renombra con prefijo .min |
|
// * 6 * // compresión producción (minificada) |
|
// * 7 * // destino producción |
|
|
|
gulp.task('sass', () => { |
|
|
|
gulp.src(sassSrc) // * 1 * // |
|
.pipe(sass({outputStyle: 'nested'})) // * 2 * // |
|
.pipe(autoprefixer('last 15 versions', '> 1%')) // * 3 * // |
|
.pipe(gulp.dest(sassDest)) // * 4 * // |
|
.pipe(rename({suffix: '.min'})) // * 5 * // |
|
.pipe(sass({outputStyle: 'compressed'})) // * 6 * // |
|
.pipe(gulp.dest(sassDest)); // * 7 * // |
|
|
|
}); |
|
|
|
// TAREA JEKYLL-BUILD (primero ejecuta la terea sass) |
|
|
|
// * 1 * // ejecuta el comando jekyll con el subcomando build |
|
|
|
gulp.task('jekyll-build', ['sass'], () => { |
|
|
|
// CONFIGURACION LOCAL |
|
// baseurl & url (vacio) |
|
|
|
const jekyll = child.spawn('jekyll', ['build']); // * 1 * // |
|
|
|
}); |
|
|
|
// TAREA JEKYLL (primero ejecuta la terea sass) |
|
|
|
// * 1 * // ejecuta el comando jekyll con el subcomando build |
|
// * 2 * // añade la opción --watch (vigila cambios) |
|
// * 3 * // añade la opción --incremental (compila solo los archivos modificados) |
|
|
|
gulp.task('jekyll', ['sass'], () => { |
|
|
|
// CONFIGURACION LOCAL |
|
// baseurl & url (vacio) |
|
|
|
const jekyll = child.spawn('jekyll', ['build', // * 1 * // |
|
'--watch', // * 2 * // |
|
'--incremental' // * 3 * // |
|
]); |
|
|
|
// CONFIGURACION DE PROD. + CONFIGURACION LOCAL |
|
// baseurl & url (definido) |
|
// añadir _config-dev.yml con baseurl & url (vacio) |
|
|
|
// * 4 * // añade la opción --config (define archivo de configuración) |
|
// * 5 * // archivos de configuración (cada archivo modofica las definiciones del anterior) |
|
|
|
/* |
|
|
|
const jekyll = child.spawn('jekyll', ['build', |
|
'--watch', |
|
'--incremental', |
|
'--config', // * 4 * // |
|
'_config.yml,_config-dev.yml' // * 5 * // |
|
]); |
|
|
|
*/ |
|
|
|
const jekyllLogger = (buffer) => { |
|
buffer.toString() |
|
.split(/\n/) |
|
.forEach((message) => gutil.log('Jekyll: ' + message)); |
|
}; |
|
|
|
jekyll.stdout.on('data', jekyllLogger); |
|
jekyll.stderr.on('data', jekyllLogger); |
|
|
|
}); |
|
|
|
// TAREA SERVE (primero ejecuta la tarea jekyll) |
|
|
|
// * 1 * // inicializa browser-sync |
|
// * 2 * // ruta donde vigila los archivos para auto-refrescar el navegador |
|
// * 3 * // puerto para el servidor local |
|
// * 4 * // ruta para montar el servidor local |
|
// * 5 * // vigila los cambios y ejecuta la tarea sass |
|
|
|
gulp.task('serve', ['jekyll'], () => { |
|
|
|
browserSync.init({ // * 1 * // |
|
files: [siteRoot + '/**'], // * 2 * // |
|
port: 4000, // * 3 * // |
|
server: { |
|
baseDir: siteRoot // * 4 * // |
|
} |
|
}); |
|
|
|
gulp.watch(('_sass/**'), ['sass']); // * 5 * // |
|
|
|
}); |
|
|
|
// TAREA DEFAULT (inicia la tarea serve al ejecutar el comando gulp) |
|
|
|
gulp.task('default', ['serve']); |