-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
116 lines (101 loc) · 3.07 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
108
109
110
111
112
113
114
115
// Include plugins ===================================================================
// Base
var gulp = require('gulp');
var replace = require('gulp-replace');
var rename = require('gulp-rename');
var pump = require('pump')
var fs = require('fs');
// CSS
var sass = require('gulp-sass');
var autoprefixer = require('gulp-autoprefixer');
var cssbeautify = require('gulp-cssbeautify');
var cssnano = require('gulp-cssnano');
// HTML
var haml = require('gulp-haml');
var htmlmin = require('gulp-htmlmin');
var injectfile = require('gulp-inject-file');
// JS
var uglify = require('gulp-uglify');
// Sync
var browserSync = require('browser-sync');
// Browser Sync ======================================================================
gulp.task('sync', function() {
browserSync({
server: {
baseDir: ''
},
})
});
// Compile HAML =======================================================================
gulp.task('html', function () {
gulp.src('_dev/html/*.haml')
.pipe(haml())
.pipe(injectfile({
pattern: '<!--\\s*inject:<filename>-->'
}))
.pipe(gulp.dest('_dev/html'))
.pipe(rename('index.html'))
.pipe(htmlmin({
collapseWhitespace: true,
collapseInlineTagWhitespace: true,
removeComments: true,
minifyCSS: true,
minifyJS: true
}))
.pipe(rename('index.html'))
.pipe(gulp.dest(''))
.pipe(browserSync.reload({
stream: true
}));
});
// Minify SVG +=======================================================================
gulp.task('svg', function () {
gulp.src('_dev/img/*.svg')
.pipe(htmlmin({
collapseWhitespace: true,
collapseInlineTagWhitespace: true,
removeComments: true,
minifyCSS: true,
minifyJS: true
}))
.pipe(gulp.dest('img'))
.pipe(browserSync.reload({
stream: true
}));
});
// Compile style.scss ================================================================
gulp.task('css', function() {
return gulp.src('_dev/css/*.scss')
.pipe(sass()).on('error', sass.logError)
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(rename('style.css'))
.pipe(gulp.dest(''))
.pipe(cssnano())
.pipe(rename('style.min.css'))
.pipe(gulp.dest('css'))
.pipe(browserSync.reload({
stream: true
}));
});
// Minify JS =========================================================================
gulp.task('js', function (cb) {
pump([
gulp.src('_dev/js/*.js'),
uglify(),
gulp.dest('js')
],
cb
);
});
// Watch Files For Changes ===========================================================
gulp.task('watch', ['sync'], function() {
gulp.watch('_dev/img/*.svg', ['svg']);
gulp.watch('_dev/html/*.haml', ['html']);
gulp.watch('_dev/css/*.scss', ['html', 'css']);
gulp.watch('_dev/js/*.js', ['js']);
});
// Default Task ======================================================================
gulp.task('default', ['watch']);