-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
97 lines (88 loc) · 2.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
const gulp = require('gulp');
const browserSync = require('browser-sync').create();
const reload = browserSync.reload;
const sass = require('gulp-sass');
const autoprefixer = require('gulp-autoprefixer');
const concat = require('gulp-concat');
const cssmin = require('gulp-cssmin');
const uglify = require('gulp-uglify');
const babel = require('gulp-babel');
const rename = require('gulp-rename');
const image = require('gulp-image');
const stripCss = require('gulp-strip-css-comments');
////Default
gulp.task('default', ['watch']);
////Server
gulp.task('server', ()=>{
browserSync.init({
server: {
baseDir: "src"
},
browser: ['chrome']
});
});
////Compile SASS to CSS (Src)
gulp.task('sass', ()=>{
return gulp.src('src/sass/global.scss')
.pipe(concat('main.css'))
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(gulp.dest('src/stylesheets'));
});
////Main CSS file to Build
gulp.task('css-build', ()=>{
return gulp.src('src/stylesheets/main.css')
.pipe(stripCss())
.pipe(gulp.dest('build/stylesheets'))
.pipe(rename({suffix: '.min'}))
.pipe(cssmin())
.pipe(stripCss())
.pipe(gulp.dest('build/stylesheets'))
});
////Bundle all JS files to Src and Build
gulp.task('js-build', ()=>{
return gulp.src(['src/js/*.js','!src/js/bundle.js'])
.pipe(concat('bundle.js'))
.pipe(babel())
.pipe(gulp.dest('src/js'))
.pipe(concat('bundle.js'))
.pipe(babel())
.pipe(gulp.dest('build/js'))
.pipe(concat('bundle.js'))
.pipe(rename({suffix: '.min'}))
.pipe(babel())
.pipe(uglify())
.pipe(gulp.dest('build/js'))
});
////All JS files to Build
gulp.task('build-scripts', ()=>{
return gulp.src(['src/js/*.js','!src/js/bundle.js'])
.pipe(babel())
.pipe(gulp.dest('build/js'))
.pipe(rename({suffix: '.min'}))
.pipe(babel())
.pipe(uglify())
.pipe(gulp.dest('build/js'))
});
////Compress images to Build
gulp.task('imagemin', ()=>{
gulp.src('src/images/**')
.pipe(image())
.pipe(gulp.dest('build/images'))
});
////All HTML files to Build
gulp.task('htmls', ()=>{
return gulp.src('src/*.html')
.pipe(gulp.dest('build'))
});
////Watch tasks
gulp.task('watch', ['server','sass','css-build','js-build','htmls'], ()=>{
gulp.watch(['src/sass/**/*'], ['sass']);
gulp.watch('src/stylesheets/*.css', ['css-build']).on('change', reload);
gulp.watch('src/js/*.js', ['js-build', 'build-scripts']).on('change', reload);
gulp.watch('src/images/*', ['imagemin']);
gulp.watch('src/*.html', ['htmls']).on('change', reload);
});