-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
135 lines (120 loc) · 3.57 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
var gulp = require('gulp');
// Includes plugins
var plugins = require('gulp-load-plugins')();
var runSequence = require('run-sequence');
// HTML
gulp.task('html', function(){
return gulp.src('src/index.html')
.pipe(gulp.dest('dist'))
.pipe(plugins.livereload());
});
// CSS
gulp.task('css', function () {
return gulp.src('src/sass/style.scss')
.pipe(plugins.wiredep())
.pipe(plugins.plumber())
.pipe(plugins.sass().on('error', plugins.sass.logError))
.pipe(plugins.autoprefixer())
.pipe(gulp.dest('dist'))
.pipe(plugins.livereload());
});
// JS
gulp.task('js', function() {
return gulp.src('src/js/site.js')
.pipe(plugins.plumber())
.pipe(gulp.dest('dist'))
.pipe(plugins.livereload());
});
// Vendors
gulp.task('vendors', ['vendors_js', 'vendors_fonts']);
gulp.task('vendors_js', function(){
return gulp.src('./bower.json')
.pipe(plugins.mainBowerFiles())
.pipe(plugins.filter('**/*.js'))
.pipe(plugins.concat('vendors.js'))
.pipe(gulp.dest('dist/vendors'));
});
gulp.task('vendors_fonts', function(){
return gulp.src('./bower_components/**/*.{eot,svg,ttf,woff,woff2}')
.pipe(plugins.flatten())
.pipe(gulp.dest('dist/fonts/'));
});
// CSS optimisation
gulp.task('css_optimisation', function () {
return gulp.src('dist/style.css')
.pipe(plugins.sourcemaps.init())
.pipe(plugins.csso())
.pipe(plugins.uncss({
html: ['src/*.html'],
ignore: [
".fade",
".fade.in",
".collapse",
".collapse.in",
".collapsing",
/\.open/
]
}))
.pipe(plugins.sourcemaps.write('.'))
.pipe(gulp.dest('dist'))
});
gulp.task('css_vendors_optimisation', function () {
return gulp.src('dist/vendors/vendors.css')
.pipe(plugins.sourcemaps.init())
.pipe(plugins.csso())
.pipe(plugins.uncss({html: ['src/*.html']}))
.pipe(plugins.sourcemaps.write('.'))
.pipe(gulp.dest('dist/vendors'))
});
// JS Optimisation
gulp.task('js_optimisation', function() {
return gulp.src('dist/site.js')
.pipe(plugins.sourcemaps.init())
.pipe(plugins.plumber())
.pipe(plugins.uglify())
.pipe(plugins.sourcemaps.write('.'))
.pipe(gulp.dest('dist'))
});
gulp.task('js_vendors_optimisation', function() {
return gulp.src('dist/vendors/vendors.js')
.pipe(plugins.sourcemaps.init())
.pipe(plugins.plumber())
.pipe(plugins.uglify())
.pipe(plugins.sourcemaps.write('.'))
.pipe(gulp.dest('dist/vendors'))
});
// Images optimisation
gulp.task('img', function () {
return gulp.src('src/img/*.{png,jpg,svg}')
.pipe(plugins.imagemin())
.pipe(gulp.dest('dist/img'));
});
// Clean
gulp.task('clean', function() {
return gulp.src('dist', {read: false})
.pipe(plugins.clean());
});
// Build
gulp.task('build', ['img', 'js', 'css', 'vendors', 'html']);
gulp.task('build:optimized', function(done) {
runSequence(
'clean', [
'build',
'css_optimisation',
'css_vendors_optimisation',
'js_optimisation',
'js_vendors_optimisation'
], function() {
done();
}
);
});
// Watch
gulp.task('watch', function(){
plugins.livereload.listen();
gulp.watch('src/*.html', ['html']);
gulp.watch('src/sass/**/*.scss',['css']);
gulp.watch('src/js/site.js',['js']);
});
// Default
gulp.task('default', ['prod']);