nunta/gulpfile.js

122 lines
2.9 KiB
JavaScript
Raw Normal View History

var gulp = require('gulp');
var sass = require('gulp-sass');
var header = require('gulp-header');
var cleanCSS = require('gulp-clean-css');
var rename = require("gulp-rename");
var uglify = require('gulp-uglify');
var pkg = require('./package.json');
2018-01-20 00:37:06 +01:00
var browserSync = require('browser-sync').create();
// Set the banner content
var banner = ['/*!\n',
2017-08-11 21:12:34 +02:00
' * Start Bootstrap - <%= pkg.title %> v<%= pkg.version %> (<%= pkg.homepage %>)\n',
' * Copyright 2013-' + (new Date()).getFullYear(), ' <%= pkg.author %>\n',
' * Licensed under <%= pkg.license %> (https://github.com/BlackrockDigital/<%= pkg.name %>/blob/master/LICENSE)\n',
' */\n',
''
].join('');
2018-01-20 00:37:06 +01:00
// Copy third party libraries from /node_modules into /vendor
gulp.task('vendor', function() {
// Bootstrap
gulp.src([
'./node_modules/bootstrap/dist/**/*',
'!./node_modules/bootstrap/dist/css/bootstrap-grid*',
'!./node_modules/bootstrap/dist/css/bootstrap-reboot*'
])
.pipe(gulp.dest('./vendor/bootstrap'))
// Font Awesome
gulp.src([
'./node_modules/font-awesome/**/*',
'!./node_modules/font-awesome/{less,less/*}',
'!./node_modules/font-awesome/{scss,scss/*}',
'!./node_modules/font-awesome/.*',
'!./node_modules/font-awesome/*.{txt,json,md}'
])
.pipe(gulp.dest('./vendor/font-awesome'))
// jQuery
gulp.src([
'./node_modules/jquery/dist/*',
'!./node_modules/jquery/dist/core.js'
])
.pipe(gulp.dest('./vendor/jquery'))
// jQuery Easing
gulp.src([
'./node_modules/jquery.easing/*.js'
])
.pipe(gulp.dest('./vendor/jquery-easing'))
});
2018-01-20 00:37:06 +01:00
// Compile SCSS
gulp.task('css:compile', function() {
return gulp.src('./scss/**/*.scss')
.pipe(sass.sync({
outputStyle: 'expanded'
}).on('error', sass.logError))
2018-05-03 07:38:23 +02:00
.pipe(header(banner, {
pkg: pkg
}))
2018-01-20 00:37:06 +01:00
.pipe(gulp.dest('./css'))
});
// Minify CSS
gulp.task('css:minify', ['css:compile'], function() {
return gulp.src([
'./css/*.css',
'!./css/*.min.css'
])
.pipe(cleanCSS())
2017-08-11 21:12:34 +02:00
.pipe(rename({
suffix: '.min'
}))
2018-01-20 00:37:06 +01:00
.pipe(gulp.dest('./css'))
.pipe(browserSync.stream());
});
2018-01-20 00:37:06 +01:00
// CSS
gulp.task('css', ['css:compile', 'css:minify']);
// Minify JavaScript
gulp.task('js:minify', function() {
return gulp.src([
'./js/*.js',
'!./js/*.min.js'
])
2017-08-11 21:12:34 +02:00
.pipe(uglify())
.pipe(rename({
suffix: '.min'
}))
2018-05-03 07:38:23 +02:00
.pipe(header(banner, {
pkg: pkg
}))
2018-01-20 00:37:06 +01:00
.pipe(gulp.dest('./js'))
.pipe(browserSync.stream());
});
2018-01-20 00:37:06 +01:00
// JS
gulp.task('js', ['js:minify']);
// Default task
2018-01-20 00:37:06 +01:00
gulp.task('default', ['css', 'js', 'vendor']);
// Configure the browserSync task
gulp.task('browserSync', function() {
2017-08-11 21:12:34 +02:00
browserSync.init({
server: {
2018-01-20 00:37:06 +01:00
baseDir: "./"
}
});
});
2018-01-20 00:37:06 +01:00
// Dev task
gulp.task('dev', ['css', 'js', 'browserSync'], function() {
gulp.watch('./scss/*.scss', ['css']);
gulp.watch('./js/*.js', ['js']);
gulp.watch('./*.html', browserSync.reload);
});