This repository has been archived by the owner on Feb 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
86 lines (75 loc) · 1.93 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
'use strict';
// Set the browser that you want to support
const AUTOPREFIXER_BROWSERS = [
'ie >= 10',
'ie_mob >= 10',
'ff >= 30',
'chrome >= 34',
'safari >= 7',
'opera >= 23',
'ios >= 7',
'android >= 4.4',
'bb >= 10'
];
// Include the required tools used on tasks
var gulp = require('gulp'),
autoprefixer = require('gulp-autoprefixer'),
jshint = require('gulp-jshint'),
rename = require('gulp-rename'),
uglify = require('gulp-uglify'),
sass = require('gulp-sass'),
csso = require('gulp-csso'),
del = require('del');
// Specify the Source files
var SRC_JS = 'src/js/*.js';
var SRC_CSS = 'src/css/*.css';
// Specify the Destination folders
var DEST_JS = 'dist/js';
var DEST_CSS = 'dist/css';
// JS TASKS
// Lint JS
gulp.task('lint:js', function() {
return gulp
.src(SRC_JS)
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'));
});
// Build JS
gulp.task('build:js', ['clean:js', 'lint:js'], function() {
return gulp
.src(SRC_JS)
.pipe(gulp.dest(DEST_JS))
.pipe(uglify({ preserveComments: 'license' }))
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest(DEST_JS));
});
// Build CSS
gulp.task('build:sass', function() {
gulp
.src('src/scss/style.scss')
.pipe(sass({ style: 'expanded' }))
.on('error', console.error.bind(console, 'Sass error:'))
// Auto-prefix css styles for cross browser compatibility
.pipe(autoprefixer({ browsers: AUTOPREFIXER_BROWSERS }))
// Minify the file
.pipe(csso())
// Output
.pipe(gulp.dest(DEST_CSS));
});
// CLEAN files
gulp.task('clean:js', function() {
return del([DEST_JS]);
});
gulp.task('clean:css', function() {
return del([DEST_CSS]);
});
// WATCH for file changes and rerun the task
gulp.task('watch', function() {
gulp.watch(SRC_JS, ['build:js']);
gulp.watch(SRC_CSS, ['build:css']);
});
// DEFAULT task
gulp.task('default', function() {
gulp.start('build:js', 'build:sass');
});