-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
71 lines (61 loc) · 1.64 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
var gulp = require('gulp');
var browserSync = require('browser-sync').create();
var sass = require('gulp-sass');
var cleanCSS = require('gulp-clean-css');
var uglify = require('gulp-uglify');
var rename = require("gulp-rename");
var reload = browserSync.reload;
// Static server
gulp.task('browser-sync', function() {
return browserSync.init({
server: {
baseDir: "./code/"
},
port:8888
});
});
// Reload all Browsers
gulp.task('bs-reload', function() {
browserSync.reload();
});
//SCSS to css
gulp.task('sass', function() {
return gulp.src('./code/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./code/'))
.pipe(reload({
stream: true
}));
});
//minify css
gulp.task('minify-css', () => {
return gulp.src('./code/*.css')
.pipe(cleanCSS({compatibility: 'ie8',keepBreaks: true}))
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest('src'));
});
//minify js
gulp.task('compress', function () {
return gulp.src('./code/*.js')
.pipe(uglify())
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest('src'));
});
//make build code
gulp.task('build', function() {
'sass',
'minify-css',
'compress';
});
//Default task
//watch file and reload browser
gulp.task('default', ['browser-sync', 'sass','minify-css','compress'], function(){
gulp.watch(['./code/*.scss'], ['sass']);
gulp.watch(['./code/*.html'], ['bs-reload']);
gulp.watch(['./code/*.js'], ['bs-reload']);
gulp.watch(['./code/*.css'], ['bs-reload']);
});