This repository has been archived by the owner on Mar 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
94 lines (72 loc) · 1.69 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
'use strict';
/* ================================
* Dependencies
* ================================ */
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var browserSync = require('browser-sync').create();
var notify = require('gulp-notify');
var jscs = require('gulp-jscs');
var jsStylish = require('gulp-jscs-stylish');
var noop = function () {};
/* ================================
* Config variables
* ================================ */
// JS Code Style options
var jscsOptions = {
src: ['src/*.js', 'src/**/*.js'],
opts: {
config : '.jscsrc'
}
};
// Uglify
var uglifyOptions = {
src: ['src/*.js'],
dest: 'dist/',
opts: {
mangle: true
}
};
// Notify options
var notifyOptions = {
sound: false
};
// Browser Sync options
var browserSyncOptions = {
watchTask: true,
open: false,
server: {
baseDir: './'
}
};
// Watch options
var watchOptions = [
'*.html',
'dist/*.js'
];
/* ================================
* Tasks
* ================================ */
// JS Code Style linting
gulp.task('js-lint', function () {
return gulp.src(jscsOptions.src)
.pipe(jscs())
.on('error', noop)
.pipe(jsStylish())
});
// Build scripts
gulp.task('compress', function() {
return gulp.src(uglifyOptions.src)
.pipe(uglify(uglifyOptions.opts))
.pipe(rename({extname:'.min.js'}))
.pipe(gulp.dest(uglifyOptions.dest));
});
// Watch
gulp.task('watch', ['compress'], function() {
browserSync.init(browserSyncOptions);
console.log(__dirname);
gulp.watch(jscsOptions.src, ['js-lint', 'compress']);
gulp.watch(watchOptions).on('change', browserSync.reload);
});
gulp.task('default', ['watch']);