Skip to content

Instantly share code, notes, and snippets.

@soen
Last active June 20, 2017 19:04
Show Gist options
  • Save soen/24e8380f13e6e0f43bfcf2176c53897e to your computer and use it in GitHub Desktop.
Save soen/24e8380f13e6e0f43bfcf2176c53897e to your computer and use it in GitHub Desktop.
/*eslint no-console: ["error", { allow: ["log", "warn", "error"] }] */
'use strict';
const gulp = require('gulp');
const debug = require('gulp-debug');
const del = require('del');
const sass = require('gulp-sass');
const sourcemaps = require('gulp-sourcemaps');
const concat = require('gulp-concat');
const postcss = require('gulp-postcss');
const autoprefixer = require('autoprefixer');
const babel = require('gulp-babel');
const rev = require('gulp-rev');
const paths = {
dist: './dist',
styles: [
/* Paths to your styles go here */
],
scripts: [
/* Paths to your scripts go here */
]
};
function styles() {
return gulp.src(paths.styles)
.pipe(debug({ title : 'Styles:' }))
.pipe(sourcemaps.init())
.pipe(sass().on('error', function (err) {
console.error('error', err.message);
this.emit('end');
}))
.pipe(concat('styles.all.css'))
.pipe(postcss([
autoprefixer({})
]))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(paths.dist + '/styles'))
}
function scripts() {
return gulp.src(paths.scripts)
.pipe(debug({ title : 'Scripts:' }))
.pipe(sourcemaps.init())
.pipe(babel({
presets: ['es2015'],
}))
.pipe(concat('scripts.all.js'))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(paths.dist + '/scripts'));
}
function revision() {
return gulp.src([
paths.dist + '/**/*.css',
paths.dist + '/**/*.js'
])
.pipe(debug({ title : 'Manifest:' }))
.pipe(sourcemaps.init())
.pipe(rev())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(paths.dist))
.pipe(rev.manifest())
.pipe(gulp.dest(paths.dist));
}
function clean() {
return del([ paths.dist ]);
}
const build = gulp.series(clean, gulp.parallel(styles, scripts), revision);
clean.description = 'Clean\'s everything up neat and tidy';
build.description = 'Build the entire site';
exports.clean = clean;
exports.build = build;
gulp.task('default', build);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment