-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
85 lines (75 loc) · 2.25 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const gulp = require('gulp');
const browserSync = require('browser-sync');
const sass = require('gulp-sass');
const sourcemaps = require('gulp-sourcemaps');
const autoprefixer = require('gulp-autoprefixer');
const cleanCSS = require('gulp-clean-css');
const uglify = require('gulp-uglify');
const concat = require('gulp-concat');
const htmlReaplace = require('gulp-html-replace');
const htmlMin = require('gulp-htmlmin');
const del = require('del');
const sequence = require('run-sequence');
gulp.task('reload', function() {
browserSync.reload();
});
gulp.task('serve', ['sass'], function() {
browserSync({
server: 'public'
})
gulp.watch('public/*.html', ['reload']);
gulp.watch('public/assets/scss/**/*.scss', ['sass']);
});
gulp.task('sass',function(){
return gulp.src('public/assets/scss/**/*.scss')
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer({
browsers: ['last 5 versions']
}))
.pipe(sourcemaps.write())
.pipe(gulp.dest('public/assets/css'))
.pipe(browserSync.stream());
});
gulp.task('CSS', function() {
return gulp.src('public/assets/css/**/*.css')
.pipe(concat('style.css'))
.pipe(gulp.dest('build/assets/css'));
});
gulp.task('minCSS', function() {
return gulp.src('public/assets/css/**/*.css')
.pipe(concat('style.min.css'))
.pipe(cleanCSS())
.pipe(gulp.dest('build/assets/css'));
});
gulp.task('JS', function() {
return gulp.src('public/assets/js/**/*.js')
.pipe(concat('script.js'))
.pipe(gulp.dest('build/assets/js'));
});
gulp.task('minJS', function() {
return gulp.src('public/assets/js/**/*.js')
.pipe(concat('script.min.js'))
.pipe(uglify())
.pipe(gulp.dest('build/assets/js'));
});
gulp.task('minHTML', function() {
return gulp.src('public/*.html')
.pipe(htmlReaplace({
'css': 'assets/css/style.css',
'js': 'assets/js/script.js'
}))
.pipe(htmlMin({
sortAttributes: true,
sortClassName: true /*,
collapseWhitespace: true */
}))
.pipe(gulp.dest('build/'));
})
gulp.task('clean',function() {
return del(['build']);
})
gulp.task('build', function() {
sequence('clean', [ 'minHTML', 'JS', 'minJS', 'CSS', 'minCSS']);
});
gulp.task('default', ['serve']);