-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
71 lines (59 loc) · 1.72 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
var gulp = require('gulp'),
rename = require('gulp-rename');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
// Server
var browserSync = require('browser-sync').create();
// Styles
var autoprefixer = require('gulp-autoprefixer');
var cssnano = require('gulp-cssnano');
var sass = require('gulp-sass');
// Scripts
var uglify = require('gulp-uglify');
var browserify = require('browserify');
gulp.task('default', ['watch'], function() {});
//**************************** Pipelines ****************************//
gulp.task('styles', function(){
gulp.src(['src/styles/**/*.scss'])
.pipe(sass())
.pipe(autoprefixer('last 2 versions'))
.pipe(rename({suffix: '.min'}))
.pipe(cssnano())
.pipe(gulp.dest('dist/styles/'))
.pipe(browserSync.reload({
stream: true
}));
});
gulp.task('scripts', function(){
return browserify('src/scripts/main.js')
.bundle()
.pipe(source('main.js'))
.pipe(buffer())
//.pipe(uglify())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('./dist/scripts/'))
.pipe(browserSync.reload({
stream: true
}));
});
gulp.task('images', function(){
gulp.src(['src/imgs/**/*'])
.pipe(gulp.dest('dist/imgs/'))
.pipe(browserSync.reload({
stream: true
}));
});
//**************************** Helpers ****************************//
gulp.task('watch', ['browserSync', 'styles', 'scripts', 'images'], function(){
gulp.watch('src/styles/**/*.scss', ['styles']);
gulp.watch('src/scripts/**/*.js', ['scripts']);
gulp.watch('src/images/**/*', ['images']);
gulp.watch('*.html', browserSync.reload);
});
gulp.task('browserSync', function() {
browserSync.init({
server: {
baseDir: '.'
},
});
});