Skip to content

Instantly share code, notes, and snippets.

Avatar
Building stuff

Brett Stevenson tterb

Building stuff
View GitHub Profile
View Gulpfile-pt8.js
// Delete CSS
gulp.task('clean:styles', function(callback) {
del([paths.jekyllCssFiles + 'main.css',
paths.siteCssFiles + 'main.css',
'_includes/critical.css'
]);
callback();
});
// Delete processed JS
View Gulpfile-pt7.js
// Run jekyll build command.
gulp.task('build:jekyll', function() {
var shellCommand = 'bundle exec jekyll build --config _config.yml';
return gulp.src('')
.pipe(run(shellCommand))
.on('error', gutil.log);
});
// Special tasks for building and reloading BrowserSync
gulp.task('build:jekyll:watch', ['build:jekyll:local'], function(callback) {
View Gulpfile-pt6.js
// Place fonts in proper location
gulp.task('build:fonts', function() {
return gulp.src(paths.fontFiles + '/**/**.*')
.pipe(rename(function(path) {path.dirname = '';}))
.pipe(gulp.dest(paths.jekyllFontFiles))
.pipe(gulp.dest(paths.siteFontFiles))
.pipe(browserSync.stream())
.on('error', gutil.log);
});
@tterb
tterb / Gulpfile-pt5.js
Last active Dec 20, 2019
Gulpfile images
View Gulpfile-pt5.js
// Optimize and copy image files
gulp.task('build:images', function() {
return gulp.src(paths.imageFilesGlob)
.pipe(imagemin({
optimizationLevel: 3,
progressive: true,
interlaced: true,
use: [pngquant()]
}))
.pipe(gulp.dest(paths.jekyllImageFiles))
@tterb
tterb / Gulpfile-pt4.js
Last active Sep 25, 2020
Gulpfile scripts
View Gulpfile-pt4.js
// Concatenate and uglify global JS files and output the result to the
// appropriate location
gulp.task('build:scripts:global', function() {
return gulp.src([
paths.jsFiles + '/lib' + paths.jsPattern,
paths.jsFiles + '/*.js'
])
.pipe(concat('main.js'))
.pipe(uglify())
.pipe(gulp.dest(paths.jekyllJsFiles))
@tterb
tterb / Gulpfile-pt3.js
Created Dec 20, 2019
Gulpfile critical
View Gulpfile-pt3.js
// Create and process critical CSS file to be included in head
gulp.task('build:styles:critical', function() {
return sass(paths.sassFiles + '/critical.scss', {
style: 'compressed',
trace: true,
loadPath: [paths.sassFiles]
}).pipe(postcss([ autoprefixer({ browsers: ['last 2 versions'] }), cssnano()]))
.pipe(gulp.dest('_includes'))
.on('error', gutil.log);
});
@tterb
tterb / Gulpfile-pt2.js
Created Dec 20, 2019
Gulpfile stylesheets
View Gulpfile-pt2.js
// Process styles, add vendor-prefixes, minify, then
// output the file to the appropriate location
gulp.task('build:styles:main', () => {
return sass(paths.sassFiles + '/main.scss', {
style: 'compressed',
trace: true,
loadPath: [paths.sassFiles]
}).pipe(postcss([autoprefixer({ browsers: ['last 2 versions']}), cssnano()]))
.pipe(gulp.dest(paths.jekyllCssFiles))
.pipe(gulp.dest(paths.siteCssFiles))
@tterb
tterb / Gulpfile.js
Created Dec 20, 2019
Jekyll Gulpfile
View Gulpfile.js
// Gulpfile.js
const autoprefixer = require('autoprefixer');
const browserSync = require('browser-sync').create();
const concat = require('gulp-concat');
const cssnano = require('cssnano');
const del = require('del');
const gulp = require('gulp');
const gutil = require('gulp-util');
const imagemin = require('gulp-imagemin');
const pngquant = require('imagemin-pngquant');
@tterb
tterb / paths.js
Last active Sep 25, 2020
Jekyll paths
View paths.js
var paths = {};
// Directory locations.
paths.assetsDir = '_assets/'; // The files Gulp will handle.
paths.jekyllDir = ''; // The files Jekyll will handle.
paths.jekyllAssetsDir = 'assets/'; // The asset files Jekyll will handle.
paths.siteDir = '_site/'; // The resulting static site.
paths.siteAssetsDir = '_site/assets/'; // The resulting static site's assets.
// Folder naming conventions.
paths.postFolder = '_posts';
@tterb
tterb / Auto nvm
Created Jul 25, 2019
Automatically switches Node versions when you `cd` into a directory with a `.nvmrc` file
View Auto nvm
find-up () {
path=$(pwd)
while [[ "$path" != "" && ! -e "$path/$1" ]]; do
path=${path%/*}
done
echo "$path"
}
cdnvm(){
cd "$@";