-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
91 lines (81 loc) · 2.62 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
// Dependencies
var gulp = require('gulp');
var sass = require('gulp-sass');
var cleanCSS = require('gulp-clean-css');
var autoprefixer = require('gulp-autoprefixer');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var browserSync = require('browser-sync').create();
var gutil = require('gulp-util');
var webp = require('gulp-webp');
// Paths
var sassFiles = 'app/**/*.scss',
jsFiles = ['app/**/*.js', '!app/lib/**/*.js', '!app/**/*.min.js', '!app/lib/**/*'],
jsxFiles = 'app/**/*.jsx',
htmlFiles = 'app/**/*.html',
images = ['app/**/*.png', 'app/**/*.jpg', 'app/**/*.gif'];
gulp.task('browserSync', function () {
browserSync.init({
server: {
baseDir: 'app'
}
})
});
// Convert our SCSS files to CSS and minify
gulp.task('styles', function () {
return gulp.src(sassFiles, { base: '.' })
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer({
browsers: ['last 3 versions'],
cascade: false
}))
.pipe(rename(function (path) {
path.dirname = path.dirname.replace('\sass', '\css');
path.extname = ".min.css";
}))
.pipe(cleanCSS())
.pipe(gulp.dest('.'))
.pipe(browserSync.reload({
stream: true
}));
});
// Concatenate our stylesheets
gulp.task('styles-concat', function () {
return gulp.src(['./app/css/lib/bootstrap.min.css', './app/css/lib/font-awesome.min.css', './app/css/style.min.css'], { base: '.' })
.pipe(concat('./app/css/styles.min.css'))
.pipe(gulp.dest('.'));
});
// Minify js files
gulp.task('scripts', function () {
return gulp.src(jsFiles, { base: '.' })
.pipe(rename(function (path) {
path.extname = ".min.js";
}))
.pipe(uglify())
.pipe(gulp.dest('.'))
.pipe(browserSync.reload({
stream: true
}));
});
// Concatenate our scripts
gulp.task('scripts-concat', function () {
return gulp.src(['./app/js/lib/jquery.min.js', './app/js/lib/bootstrap.min.js', './app/js/app.min.js'], { base: '.' })
.pipe(concat('./app/js/scripts.min.js'))
.pipe(gulp.dest('.'));
});
// Compress images to webp format
gulp.task('images', function () {
return gulp.src(images, { base: '.' })
.pipe(gulp.dest('.'));
});
// Build task for deployment
gulp.task('build', ['images', 'styles', 'styles-concat', 'scripts', 'scripts-concat'], function () {
});
// Watch our files for changes during development
gulp.task('watch', ['build', 'browserSync'], function () {
gulp.watch(sassFiles, ['styles', 'styles-concat']);
gulp.watch(jsFiles, ['scripts', 'scripts-concat']);
gulp.watch(jsxFiles, browserSync.reload);
gulp.watch(htmlFiles, browserSync.reload);
});