Created
April 13, 2016 16:33
-
-
Save matallo/f3f39f0345ffbd59cb88dc51b62fe200 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import gulp from 'gulp'; | |
import gulpLoadPlugins from 'gulp-load-plugins'; | |
import browserSync from 'browser-sync'; | |
import del from 'del'; | |
import childProcess from 'child_process'; | |
const $ = gulpLoadPlugins(); | |
const reload = browserSync.reload; | |
gulp.task('jekyll-serve', (done) => { | |
return childProcess.spawn('bundle', ['exec', 'jekyll', 'build', '-q', '--incremental', '--config=_config.yml', '--limit', '30'], { stdio: 'inherit' }) | |
.on('close', done); | |
}); | |
gulp.task('jekyll-build', (done) => { | |
return childProcess.spawn('bundle', ['exec', 'jekyll', 'build', '-q', '--config=_config.yml,_config-prod.yml'], { stdio: 'inherit' }) | |
.on('close', done); | |
}); | |
gulp.task('styles', () => { | |
return gulp.src('_app/_scss/*.scss') | |
.pipe($.plumber()) | |
.pipe($.sourcemaps.init()) | |
.pipe($.sass.sync({ | |
outputStyle: 'expanded', | |
precision: 10, | |
includePaths: ['.'] | |
}).on('error', $.sass.logError)) | |
.pipe($.autoprefixer({browsers: ['> 1%', 'last 2 versions', 'Firefox ESR']})) | |
.pipe($.sourcemaps.write()) | |
.pipe(gulp.dest('.tmp/css')) | |
.pipe(reload({stream: true})); | |
}); | |
gulp.task('scripts', () => { | |
return gulp.src('_app/_js/**/*.js') | |
.pipe($.plumber()) | |
.pipe($.sourcemaps.init()) | |
.pipe($.babel()) | |
.pipe($.sourcemaps.write('.')) | |
.pipe(gulp.dest('.tmp/js')) | |
.pipe(reload({stream: true})); | |
}); | |
function lint(files, options) { | |
return () => { | |
return gulp.src(files) | |
.pipe(reload({stream: true, once: true})) | |
.pipe($.eslint(options)) | |
.pipe($.eslint.format()) | |
.pipe($.if(!browserSync.active, $.eslint.failAfterError())); | |
}; | |
} | |
// const testLintOptions = { | |
// env: { | |
// mocha: true | |
// } | |
// }; | |
gulp.task('lint', lint('_app/js/**/*.js')); | |
// gulp.task('lint:test', lint('test/spec/**/*.js', testLintOptions)); | |
gulp.task('html', ['jekyll-build', 'styles', 'scripts'], () => { | |
return gulp.src('_site/**/*.html') | |
.pipe($.useref({searchPath: ['.tmp', '_site', '.']})) | |
.pipe($.if('*.js', $.uglify())) | |
.pipe($.if('*.css', $.cssnano())) | |
.pipe($.if('*.html', $.htmlmin({collapseWhitespace: true}))) | |
.pipe(gulp.dest('_dist')); | |
}); | |
gulp.task('images', () => { | |
return gulp.src('_site/img/**/*') | |
.pipe($.cache($.imagemin({ | |
progressive: true, | |
interlaced: true, | |
// don't remove IDs from SVGs, they are often used | |
// as hooks for embedding and styling | |
svgoPlugins: [{cleanupIDs: false}] | |
}))) | |
.pipe(gulp.dest('_dist/img')); | |
}); | |
gulp.task('extras', () => { | |
return gulp.src([ | |
'_site/*.*', | |
'!_site/*.html' | |
], { | |
dot: true | |
}).pipe(gulp.dest('_dist')); | |
}); | |
gulp.task('clean', del.bind(null, ['.tmp', '_site', '_dist'])); | |
gulp.task('serve', ['jekyll-serve', 'styles', 'scripts'], () => { | |
browserSync({ | |
notify: false, | |
port: 9000, | |
server: { | |
baseDir: ['.tmp', '_site'], | |
routes: { | |
'/bower_components': 'bower_components' | |
} | |
} | |
}); | |
gulp.watch([ | |
'_app/**/*.{md,html}', | |
'_app/img/**/*', | |
// '_app/fonts/**/*', | |
], ['jekyll-serve']); | |
gulp.watch([ | |
'_site/**/*.html', | |
'_site/img/**/*', | |
// '_site/fonts/**/*' | |
]).on('change', reload); | |
gulp.watch('_app/_scss/**/*.scss', ['styles']); | |
gulp.watch('_app/_js/**/*.js', ['scripts']); | |
}); | |
gulp.task('serve:dist', () => { | |
browserSync({ | |
notify: false, | |
port: 9000, | |
server: { | |
baseDir: ['_dist'] | |
} | |
}); | |
}); | |
// gulp.task('serve:test', ['scripts'], () => { | |
// browserSync({ | |
// notify: false, | |
// port: 9000, | |
// ui: false, | |
// server: { | |
// baseDir: 'test', | |
// routes: { | |
// '/scripts': '.tmp/scripts', | |
// '/bower_components': 'bower_components' | |
// } | |
// } | |
// }); | |
// gulp.watch('_app/scripts/**/*.js', ['scripts']); | |
// gulp.watch('test/spec/**/*.js').on('change', reload); | |
// gulp.watch('test/spec/**/*.js', ['lint:test']); | |
// }); | |
gulp.task('build', ['lint', 'html', 'images', 'extras'], () => { | |
return gulp.src('_dist/**/*').pipe($.size({title: 'build', gzip: true})); | |
}); | |
gulp.task('default', ['clean'], () => { | |
gulp.start('build'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment