-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
89 lines (76 loc) · 2.49 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
const gulp = require('gulp');
const sass = require('gulp-sass');
const browserSync = require('browser-sync').create();
const useref = require('gulp-useref');
const uglify = require('gulp-uglify');
const gulpIf = require('gulp-if');
const cssnano = require('gulp-cssnano');
const imagemin = require('gulp-imagemin');
const cache = require('gulp-cache');
const del = require('del');
const runSequence = require('run-sequence');
const babel = require('gulp-babel');
/* BROWSERSYNC TASK */
gulp.task('browserSync', function() {
browserSync.init({
server: {
baseDir: 'app'
},
});
});
/* SASS TASK */
gulp.task('sass', function() {
return gulp.src('app/resources/css/main.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('dist/css'))
.pipe(gulp.dest('app/resources/css/'))
.pipe(browserSync.reload({
stream: true
}));
});
/* USEREF TASK */
gulp.task('useref', function(){
return gulp.src('app/*.html')
.pipe(useref())
//Translate es6 to es5 for uglify
.pipe(gulpIf('*.js', babel({
presets: ['es2015']
})))
// Minifies only if it's a JavaScript file
.pipe(gulpIf('*.js', uglify()))
// Minifies only if it's a CSS file
.pipe(gulpIf('*.css', cssnano()))
.pipe(gulp.dest('dist'));
});
/* IMAGES TASK */
gulp.task('images', function(){
return gulp.src(['app/resources/images/*', 'app/resources/css/images/*'])
.pipe(cache(imagemin()))
.pipe(gulp.dest('dist/images'));
});
/* FONTS TASK */
gulp.task('fonts', function() {
return gulp.src('app/vendors/fonts/*')
.pipe(gulp.dest('dist/fonts'));
});
/* Clean up task */
gulp.task('clean-dist', function() {
return del.sync('dist');
});
/* Gulp watch file - watches for changes to any file */
gulp.task('watch', ['browserSync', 'sass'], function() {
gulp.watch('app/resources/css/**/*.scss', ['sass']);
gulp.watch('app/*.html', browserSync.reload);
gulp.watch(['app/resources/js/**/*.js', 'app/vendors/js/*.js', 'app/vendors/css/*.css'], browserSync.reload);
});
/* Build tasks */
gulp.task('build', ['clean-dist', 'fonts', 'images', 'useref']);
// gulp.task('build', function(callback) {
// runSequence('clean:dist','sass', ['useref', 'images', 'fonts'],
// callback
// );
// });
// gulp.task('default', function(done){
// runSequence('sass', 'browserSync', 'watch', done());
// });
gulp.task('default',['sass', 'browserSync', 'watch']);