-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
62 lines (53 loc) · 1.54 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
var gulp = require('gulp');
var watch = require('gulp-watch');
var plumber = require('gulp-plumber');
var browsersync = require('browser-sync');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var rename = require("gulp-rename");
var sourcemaps = require('gulp-sourcemaps');
var sass = require('gulp-sass');
var prefixer = require('gulp-autoprefixer');
var minifycss = require('gulp-minify-css');
var reload = browsersync.reload;
var paths = {
styles: "src/sass/**/*.scss",
scripts: "src/js/*.js"
};
gulp.task('watch', function() {
gulp.watch(paths.scripts, ['js']);
gulp.watch(paths.styles, ['sass']);
gulp.watch("./*.html").on('change', reload);
});
gulp.task('browser-sync', function() {
browsersync.init({
server: {
baseDir: "./"
}
});
});
gulp.task('sass', function(){
return gulp.src(paths.styles)
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(prefixer({browsers: ['last 2 versions']}))
.pipe(sourcemaps.write('./'))
.pipe(rename({suffix: '.min'}))
.pipe(minifycss())
.pipe(gulp.dest('build/css'))
.pipe(reload({stream: true}));
});
gulp.task('js', function(){
return gulp.src('src/js/*.js')
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(concat('all.js'))
.pipe(sourcemaps.write())
.pipe(gulp.dest('build/js'))
.pipe(rename('all.min.js'))
.pipe(uglify())
.pipe(gulp.dest('build/js'))
.pipe(reload({stream: true}));
});
gulp.task('default', ['sass', 'js', 'browser-sync', 'watch']);