-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
107 lines (96 loc) · 3.09 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
98
99
100
101
102
103
104
105
106
107
// node.js Packages / Dependencies
const gulp = require('gulp');
const sass = require('gulp-sass');
const uglify = require('gulp-uglify');
const rename = require('gulp-rename');
const concat = require('gulp-concat');
const cleanCSS = require('gulp-clean-css');
const imageMin = require('gulp-imagemin');
const pngQuint = require('imagemin-pngquant');
const browserSync = require('browser-sync').create();
const autoprefixer = require('gulp-autoprefixer');
const jpgRecompress = require('imagemin-jpeg-recompress');
const clean = require('gulp-clean');
// Paths
var paths = {
root: {
www: './public_html'
},
src: {
root: 'public_html/assets',
html: 'public_html/**/*.html',
css: 'public_html/assets/css/*.css',
js: 'public_html/assets/js/*.js',
vendors: 'public_html/assets/vendors/**/*.*',
imgs: 'public_html/assets/imgs/**/*.+(png|jpg|gif|svg)',
scss: 'public_html/assets/scss/**/*.scss'
},
dist: {
root: 'public_html/dist',
css: 'public_html/dist/css',
js: 'public_html/dist/js',
imgs: 'public_html/dist/imgs',
vendors: 'public_html/dist/vendors'
}
}
// Compile SCSS
gulp.task('sass', function() {
return gulp.src(paths.src.scss)
.pipe(sass({outputStyle: 'expanded'}).on('error', sass.logError))
.pipe(autoprefixer())
.pipe(gulp.dest(paths.src.root + '/css'))
.pipe(browserSync.stream());
});
// Minify + Combine CSS
gulp.task('css', function() {
return gulp.src(paths.src.css)
.pipe(cleanCSS({compatibility: 'ie8'}))
.pipe(concat('leadmark.css'))
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest(paths.dist.css))
});
// Minify + Combine JS
gulp.task('js', function() {
return gulp.src(paths.src.js)
.pipe(uglify())
.pipe(concat('leadmark.js'))
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest(paths.dist.js))
.pipe(browserSync.stream());
});
// Compress (JPEG, PNG, GIF, SVG, JPG)
gulp.task('img', function(){
return gulp.src(paths.src.imgs)
.pipe(imageMin([
imageMin.gifsicle(),
imageMin.jpegtran(),
imageMin.optipng(),
imageMin.svgo(),
pngQuint(),
jpgRecompress()
]))
.pipe(gulp.dest(paths.dist.imgs));
});
// copy vendors to dist
gulp.task('vendors', function(){
return gulp.src(paths.src.vendors)
.pipe(gulp.dest(paths.dist.vendors))
});
// clean dist
gulp.task('clean', function () {
return gulp.src(paths.dist.root)
.pipe(clean());
});
// Prepare all assets for production
gulp.task('build', gulp.series('sass', 'css', 'js', 'vendors', 'img'));
// Watch (SASS, CSS, JS, and HTML) reload browser on change
gulp.task('watch', function() {
browserSync.init({
server: {
baseDir: paths.root.www
}
})
gulp.watch(paths.src.scss, gulp.series('sass'));
gulp.watch(paths.src.js).on('change', browserSync.reload);
gulp.watch(paths.src.html).on('change', browserSync.reload);
});