-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
51 lines (48 loc) · 1.5 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
const gulp = require('gulp');
const sass = require('gulp-sass');
const cssnano = require('gulp-cssnano');
const concat = require('gulp-concat');
const autoprefixer = require('gulp-autoprefixer');
const browserSync = require('browser-sync').create();
const babel = require('gulp-babel');
const uglify = require('gulp-uglify');
const sourcemaps = require ('gulp-sourcemaps');
gulp.task('sass', function() {
return gulp.src('src/sass/main.scss')
.pipe(sourcemaps.init())
.pipe(concat('style.scss'))
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(cssnano())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('public/css'))
.pipe(browserSync.reload({stream: true}));
});
gulp.task('js', function(){
return gulp.src('src/js/**/*.js')
.pipe(sourcemaps.init())
.pipe(babel({
presets: ['env']
}))
.pipe(concat('theme.js'))
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('public/js'))
.pipe(browserSync.reload({stream: true}));
});
gulp.task('browserSync', function() {
browserSync.init({
server: {
baseDir: './public'
},
})
});
gulp.task('watch', ['browserSync', 'sass', 'js'], function (){
gulp.watch('src/sass/**/*.scss', ['sass'], browserSync.reload);
gulp.watch('src/js/**/*.js', ['js'], browserSync.reload);
// Reloads the browser whenever HTML or JS files change
gulp.watch('public/*.html', browserSync.reload);
});