-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
58 lines (50 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
52
53
54
55
56
57
58
const gulp = require('gulp');
// CSS
const sass = require('gulp-sass')(require('sass'));
const sourcemaps = require('gulp-sourcemaps');
const postcss = require('gulp-postcss');
const cssnano = require('cssnano');
const autoprefixer = require('autoprefixer');
const groupMediaQueries = require('gulp-group-css-media-queries');
// JS
const babel = require('gulp-babel');
const uglify = require('gulp-uglify');
const concat = require('gulp-concat');
const browserSync = require('browser-sync').create();
gulp.task('html', function() {
return gulp.src('index.html')
.pipe(browserSync.stream());
});
gulp.task('css', function() {
return gulp.src('sass/main.sass')
.pipe(sourcemaps.init())
.pipe(sass({ outputStyle: 'expanded' }))
.pipe(groupMediaQueries())
.pipe(postcss([
autoprefixer({ overrideBrowserslist: ['last 4 versions'] }),
cssnano()
]))
.pipe(sourcemaps.write())
.pipe(gulp.dest('css'))
.pipe(browserSync.stream({ match: '**/*.css' }));
});
gulp.task('js', function() {
return gulp.src('js/main.js')
.pipe(babel({ presets: ['@babel/env'] }))
.pipe(uglify())
.pipe(concat('main.min.js'))
.pipe(gulp.dest('js'))
.pipe(browserSync.stream());
});
gulp.task('default', gulp.series('html', 'css', function(done) {
browserSync.init({
server: {
baseDir: './'
},
notify: false
});
gulp.watch('*.html', gulp.series('html'));
gulp.watch('sass/**', gulp.series('css'));
gulp.watch('js/main.js', gulp.series('js'));
done();
}));