forked from brianeto/gulp-sass-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
65 lines (60 loc) · 1.66 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
const
gulp = require('gulp'),
sass = require('gulp-sass'),
postcss = require('gulp-postcss'),
autoprefixer = require('autoprefixer'),
babel = require('gulp-babel')
uglify = require('gulp-uglify'),
imagemin = require('gulp-imagemin'),
browserSync = require('browser-sync').create();
// sass tasks
gulp.task('sass', () =>
gulp.src('src/scss/main.scss')
.pipe(postcss([autoprefixer()]))
.pipe(sass({
sourceComments: false,
outputStyle: 'compressed'
}))
.pipe(gulp.dest('dist/css/'))
.pipe(browserSync.stream())
);
// javascript tasks
gulp.task('js', () =>
gulp.src('src/js/main.js')
.pipe(babel({ presets: ['env'] }))
.pipe(uglify())
.pipe(gulp.dest('dist/js/'))
);
// sass lint ftw(for better coding practices)
gulp.task('sass_lint', lintCssTask = () => {
const gulpStylelint = require('gulp-stylelint');
return gulp
.src('src/scss/**/*.scss')
.pipe(gulpStylelint({
reporters: [
{ formatter: 'string', console: true }
]
}));
});
// images optimization works with jpeg, jpg, svg, gif, png
gulp.task('images', () =>
gulp.src('src/images/*')
.pipe(imagemin({ verbose: true }))
.pipe(gulp.dest('dist/images/'))
);
// Just copy/paste html to distribution folder
gulp.task('html', () =>
gulp.src('src/index.html')
.pipe(gulp.dest('dist/'))
);
// Static Server + watching html/scss/js files
gulp.task('default', ['sass', 'js', 'images', 'html'], () => {
browserSync.init({
server: {
baseDir: 'dist/'
}
});
gulp.watch('src/scss/**/*.scss', ['sass']);
gulp.watch('src/js/main.js', ['js']);
gulp.watch('src/index.html').on('change', browserSync.reload);
});