Skip to content

Instantly share code, notes, and snippets.

@halex2005
Last active April 29, 2021 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save halex2005/af7ee215c27d22dd6bf5 to your computer and use it in GitHub Desktop.
Save halex2005/af7ee215c27d22dd6bf5 to your computer and use it in GitHub Desktop.
gulpfile for codeofcliber blog
var gulp = require('gulp');
var shell = require('gulp-shell');
var htmlmin = require('gulp-htmlmin');
gulp.task('htmlmin', function() {
return gulp.src('./_site/**/*.html')
.pipe(htmlmin({
collapseWhitespace: true,
removeComments: true,
conservativeCollapse: true,
collapseBooleanAttributes: true,
removeRedundantAttributes: true,
removeEmptyAttributes: true,
removeEmptyElements: false,
lint: false,
minifyJS: true,
minifyCSS: true,
}))
.pipe(gulp.dest('./_site/'));
});
var imagemin = require('gulp-imagemin');
gulp.task('imagemin', function () {
return gulp.src('./_site/images/*.png')
.pipe(imagemin([imagemin.optipng({optimizationLevel: 5})]))
.pipe(gulp.dest('./_site/images'));
});
var cleanCss = require('gulp-clean-css');
var autoprefixer = require('gulp-autoprefixer');
gulp.task('build-css', function() {
return gulp.src('_site/css/**/*.css')
.pipe(cleanCss({compatibility: 'ie8'}))
.pipe(autoprefixer({
browsers: ['> 1%'],
cascade: false
}))
.pipe(gulp.dest('./_site/css'));
});
var jsValidate = require('gulp-jsvalidate');
var uglify = require('gulp-uglify');
gulp.task('build-js', function() {
return gulp.src('./_site/js/**/*.js')
.pipe(jsValidate())
.pipe(uglify())
.pipe(gulp.dest('./_site/js/'));
});
gulp.task('copy_bower_components', function() {
gulp.src([
'bower_components/bootstrap/dist/css/bootstrap.min.css',
'bower_components/bootstrap/dist/css/bootstrap-theme.min.css',
'bower_components/fontawesome/css/font-awesome.min.css',
'bower_components/normalize.css/normalize.css'
]).pipe(gulp.dest('./_site/vendor/css/'));
gulp.src([
'bower_components/bootstrap/dist/fonts/*',
'bower_components/fontawesome/fonts/*',
]).pipe(gulp.dest('./_site/vendor/fonts/'));
gulp.src([
'bower_components/bootstrap/dist/js/bootstrap.min.js',
'bower_components/jquery/dist/jquery.min.js',
]).pipe(gulp.dest('./_site/vendor/js/'));
gulp.src([
'bower_components/modernizr/modernizr.js',
]).pipe(uglify())
.pipe(gulp.dest('./_site/vendor/js/'));
});
gulp.task('jekyll', shell.task(['jekyll build']));
gulp.task('build', ['jekyll'], function() {
gulp.run('copy_bower_components');
gulp.run('build-css');
gulp.run('htmlmin');
gulp.run('imagemin');
});
// check tasks
var bootlint = require('gulp-bootlint');
var html5Lint = require('gulp-html5-lint');
var htmlhint = require("gulp-htmlhint");
gulp.task('check-html', function() {
return gulp.src('./_site/**/*.html')
.pipe(html5Lint())
.pipe(htmlhint())
.pipe(bootlint());
});
var scsslint = require('gulp-scss-lint');
gulp.task('check-scss', function() {
gulp.src([ './_sass/**/*.scss' ])
.pipe(scsslint())
});
gulp.task('check', [ 'check-html', 'check-scss' ], function() {});
// serve task
gulp.task('jekyll-watch', shell.task(['jekyll build --watch --incremental']));
var browserSync = require('browser-sync').create();
gulp.task('webserver', function () {
browserSync.init({
port: 4000,
open: true,
reloadThrottle: 500,
reloadDebounce: 500,
server: {
baseDir: '_site/'
}
});
setTimeout(function () {
gulp.watch('_site/**/*.*').on('change', browserSync.reload);
}, 5000);
})
gulp.task('serve', ['jekyll-watch', 'copy_bower_components', 'webserver'], function () {});
// default task
gulp.task('default', [ 'build' ], function() {});
{
"name": "hal-blog",
"version": "1.0.0",
"description": "My blog based on Jekyll",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git@bitbucket.org:halex2005/hal-blog.git"
},
"keywords": [
"jekyll",
"blog"
],
"author": "halex2005",
"license": "BSD-2-Clause",
"devDependencies": {
"browser-sync": "^2.18.8",
"gulp-autoprefixer": "^3.1.1",
"gulp-bootlint": "^0.8.1",
"gulp-clean-css": "^3.0.0",
"gulp-html5-lint": "^1.1.0",
"gulp-htmlhint": "^0.3.1",
"gulp-htmlmin": "^3.0.0",
"gulp-imagemin": "^3.2.0",
"gulp-jsvalidate": "^3.0.0",
"gulp-scss-lint": "^0.4.0",
"gulp-shell": "^0.6.3",
"gulp-uglify": "^2.1.2"
}
}
@halex2005
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment