-
Notifications
You must be signed in to change notification settings - Fork 10
/
gulpfile.js
86 lines (76 loc) · 1.89 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
'use strict';
var autoprefixer = require('gulp-autoprefixer');
var browserify = require('browserify');
var browserSync = require('browser-sync').create();
var buffer = require('vinyl-buffer');
var gulp = require('gulp');
var plumber = require('gulp-plumber');
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var source = require('vinyl-source-stream');
var uglify = require('gulp-uglify');
var watch = require('gulp-watch');
var watchify = require('watchify');
/**
* Sass
*/
gulp.task('sass', function () {
return gulp.src('./assets/_sass/**/*')
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(autoprefixer({
browsers: ['> 1%', 'last 2 versions', 'Firefox ESR']
}))
.pipe(sourcemaps.write('../maps'))
.pipe(gulp.dest('./assets/css'))
.pipe(browserSync.stream());
});
/**
* Browserify and Watchify
*/
var b = browserify({
entries: ['./assets/_js/main.js'],
debug: true
});
function bundle() {
return b.bundle()
.pipe(source('bundle.js'))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(uglify())
.pipe(sourcemaps.write('../maps'))
.pipe(gulp.dest('./assets/js'))
.pipe(browserSync.stream());
}
gulp.task('browserify', bundle);
gulp.task('watchify', function () {
b = watchify(b);
b.on('update', bundle);
});
/**
* Browsersync
*/
gulp.task('browsersync', function () {
browserSync.init({
server: {
baseDir: "./"
}
});
});
/**
* Watch
*/
gulp.task('watch', ['watchify'], function () {
gulp.watch('./assets/_sass/**/*', ['sass']);
gulp.watch([
'./**/*.html'
]).on('change', browserSync.reload);
});
/**
* Build
*/
gulp.task('build', ['sass', 'browserify']);
/**
* Default
*/
gulp.task('default', ['sass', 'browserify', 'browsersync', 'watch']);