-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
113 lines (94 loc) · 2.6 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
'use strict';
// Import all required modules
var gulp = require('gulp');
var del = require('del');
var htmlmin = require('gulp-htmlmin');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var jshint = require('gulp-jshint');
var sass = require('gulp-sass');
var cleanCSS = require('gulp-clean-css');
var rename = require('gulp-rename');
var maps = require('gulp-sourcemaps');
// Image optimisation
var imagemin = require('gulp-imagemin')
var jpeg = require('imagemin-jpegtran');
var png = require('imagemin-pngquant');
var browserSync = require('browser-sync');
// HTML minification
gulp.task('htmlmin', () => {
return gulp.src('index.html')
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest('dist'));
});
// Concatenate, minify, copy JavaScript file to dist folder
gulp.task('scripts', ['minify-js']);
// Minify JavaScript and place into dist folder
gulp.task('minify-js', ['concat'], () => {
return gulp.src('dist/scripts/app.js')
.pipe(uglify())
.pipe(rename('all.min.js'))
.pipe(gulp.dest('dist/scripts'))
});
// Concatenate JavaScript files
gulp.task('concat', () => {
return gulp.src('js/**/*.js')
.pipe(maps.init())
.pipe(concat('app.js'))
.pipe(maps.write('./'))
.pipe(gulp.dest('dist/scripts'));
});
// This task perform Compile Sass and Minify CSS
gulp.task('styles', ['minify-css']);
// Minify CSS
gulp.task('minify-css', ['compile-css'], () => {
return gulp.src('dist/styles/*.css')
.pipe(maps.init())
.pipe(cleanCSS())
.pipe(maps.write())
.pipe(rename('all.min.css'))
.pipe(gulp.dest('dist/styles'));
});
// Compile Sass into CSS
gulp.task('compile-css', () => {
return gulp.src("sass/global.scss")
.pipe(sass())
.pipe(gulp.dest('dist/styles'));
});
// Optimise images
gulp.task('images', () => {
return gulp.src(['images/*.*'])
.pipe(imagemin({
progressive: true,
use: [jpeg(),png()]
}))
.pipe(gulp.dest('dist/content'));
});
// Lint JavaScript
gulp.task('lint', function() {
return gulp.src('js/circle/circle.js')
.pipe(jshint())
.pipe(jshint.reporter("default"))
.pipe(jshint.reporter("fail"));
});
// Clean dist folder before starting build process
gulp.task('clean', () => {
return del(['css', 'dist']);
});
// Build task
gulp.task('build', ['htmlmin', 'scripts', 'styles', 'images'], () => {
gulp.src('icons/**', { base : './' })
.pipe(gulp.dest('dist'));
});
// watch files for changes and reload
gulp.task('serve', () => {
browserSync({
server: {
baseDir: 'dist'
}
});
});
// Main task
gulp.task('default', ['clean', 'lint'], () => {
gulp.start('build');
});