forked from attkins/workshop-wpo-creative
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
executable file
·110 lines (97 loc) · 3.07 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
var gulp = require('gulp');
var concat = require('gulp-concat');
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 critical = require('critical').stream;
var pkg = require('./package.json');
var compress = require('compression');
var browserSync = require('browser-sync').create();
var pump = require('pump');
// Set the banner content
var banner = ['/*!\n',
' * 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('');
// Minify JavaScript
gulp.task('js:minify', function (cb) {
pump([
gulp.src('./js/*.js'),
uglify(),
gulp.dest('./dist/js')
],
cb
);
browserSync.stream();
});
gulp.task('js:concat', function() {
return gulp.src([
'./node_modules/jquery/dist/jquery.min.js',
'./node_modules/jquery.easing/jquery.easing.min.js',
'./node_modules/magnific-popup/dist/jquery.magnific-popup.min.js',
'./node_modules/bootstrap/dist/js/bootstrap.bundle.min.js',
'./node_modules/scrollreveal/dist/scrollreveal.min.js',
'./dist/js/creative.min.js'
])
.pipe(concat('all-scripts.min.js'))
.pipe(gulp.dest('./dist/js'));
});
// JS
gulp.task('js', ['js:minify', 'js:concat']);
gulp.task('html', function() {
return gulp.src('./index.html')
.pipe(gulp.dest('./dist'))
});
gulp.task('images', function() {
return gulp.src('./img/**/*')
.pipe(gulp.dest('dist/img'))
});
gulp.task('fonts', function() {
return gulp.src('./fonts/**/*')
.pipe(gulp.dest('dist/fonts'))
});
// Compile SCSS
gulp.task('css', function() {
return gulp.src('./scss/**/*.scss')
.pipe(sass.sync({
outputStyle: 'expanded'
}).on('error', sass.logError))
.pipe(gulp.dest('./dist/css'))
.pipe(cleanCSS())
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest('./dist/css'))
.pipe(browserSync.stream());
});
// Generate & Inline Critical-path CSS
gulp.task('critical', function () {
return gulp.src('dist/*.html')
.pipe(critical({base: 'dist/', inline: true, css: ['dist/css/creative.min.css']}))
.on('error', function(err) { console.log(err.message); })
.pipe(gulp.dest('dist'));
});
// Default task
gulp.task('default', ['html', 'css', 'js', 'images', 'fonts']);
// Configure the browserSync task
gulp.task('browserSync', function() {
browserSync.init({
startPath: "/dist",
server: {
baseDir: '.',
middleware: [compress()]
}
});
});
// Dev task
gulp.task('dev', ['browserSync', 'css', 'js', 'html', 'images', 'fonts', 'critical'], function() {
gulp.watch('./scss/**/*.scss', ['css', browserSync.reload]);
gulp.watch('./js/*.js', ['js']);
// Reloads the browser whenever HTML or JS files change
gulp.watch('./*.html', ['html', browserSync.reload]);
});