oliverdavies.uk/gulpfile.js

74 lines
2.5 KiB
JavaScript
Raw Normal View History

2017-08-03 00:14:30 +00:00
'use strict';
var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();
var config = require('./gulpfile.config')(plugins);
2017-08-18 21:23:07 +00:00
var del = require('del');
2017-08-03 00:14:30 +00:00
2017-08-18 21:23:07 +00:00
var app = {};
2017-08-03 00:14:30 +00:00
2017-08-18 21:23:07 +00:00
app.copy = function (sourceFiles, destination) {
return gulp.src(sourceFiles)
.pipe(gulp.dest(destination));
};
2017-08-03 00:14:30 +00:00
2017-10-08 08:26:41 +00:00
app.css = function (sourceFiles, outputFile) {
2017-08-18 21:23:07 +00:00
return gulp.src(sourceFiles)
.pipe(plugins.plumber())
.pipe(plugins.if(!config.production, plugins.sourcemaps.init()))
.pipe(plugins.sassGlob())
2017-10-07 08:00:03 +00:00
.pipe(plugins.less())
2017-10-08 08:26:41 +00:00
.pipe(plugins.autoprefixer(config.less.autoprefixer))
2017-08-18 21:23:07 +00:00
.pipe(plugins.concat(outputFile))
2017-10-08 08:26:41 +00:00
.pipe(plugins.if(config.production, plugins.purifycss(config.less.purifyCss)))
2017-08-18 21:23:07 +00:00
.pipe(plugins.if(config.production, plugins.cleanCss()))
.pipe(plugins.if(!config.production, plugins.sourcemaps.write('.')))
.pipe(plugins.if(!config.production, plugins.refresh()))
2017-10-08 08:26:41 +00:00
.pipe(gulp.dest(config.less.outputDir));
2017-08-18 21:23:07 +00:00
};
app.js = function (sourceFiles, outputFile) {
return gulp.src(sourceFiles)
.pipe(plugins.plumber())
.pipe(plugins.if(!config.production, plugins.sourcemaps.init()))
.pipe(plugins.concat(outputFile))
.pipe(plugins.if(config.production, plugins.uglify()))
.pipe(plugins.if(!config.production, plugins.sourcemaps.write('.')))
.pipe(gulp.dest(config.js.outputDir));
};
gulp.task('clean', function () {
del.sync('source/assets/{css,fonts,js}');
del.sync('output_*/assets/{css,fonts,js}');
});
2017-08-03 00:14:30 +00:00
gulp.task('default', ['clean', 'fonts', 'styles', 'scripts']);
2017-08-18 21:23:07 +00:00
gulp.task('fonts', function () {
return app.copy('node_modules/font-awesome/fonts/*', config.fonts.outputDir);
});
gulp.task('styles', function () {
2017-10-08 08:26:41 +00:00
app.css([
2017-08-03 00:39:46 +00:00
'node_modules/font-awesome/css/font-awesome.css',
2017-10-08 08:26:41 +00:00
'node_modules/prismjs/themes/prism-twilight.css',
config.less.sourceDir + '/main.less'
], 'site.css');
2017-08-18 21:23:07 +00:00
});
2017-08-03 00:39:46 +00:00
2017-08-18 21:23:07 +00:00
gulp.task('scripts', function () {
2017-08-18 23:28:44 +00:00
app.js([
2017-08-03 00:39:46 +00:00
'node_modules/jquery/dist/jquery.js',
'node_modules/prismjs/prism.js',
2017-08-06 18:01:22 +00:00
'node_modules/prismjs/components/prism-{apacheconf,bsash,css,diff,ini,json,nginx,php,sass,scss,sql,less,twig,xml,yaml}.js',
2017-10-08 08:26:41 +00:00
config.js.sourceDir + '/**/*.js'
], 'site.js')
2017-08-18 21:23:07 +00:00
});
gulp.task('watch', ['default'], function () {
plugins.refresh.listen();
2017-08-03 00:14:30 +00:00
2017-10-08 08:26:41 +00:00
gulp.watch(config.less.sourceDir + config.less.pattern, ['styles']);
2017-08-18 21:23:07 +00:00
gulp.watch(config.js.sourceDir + config.js.pattern, ['scripts']);
});