-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgulpfile.js
91 lines (81 loc) · 2.33 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
const gulp = require('gulp');
const jshint = require('gulp-jshint');
const clean = require('gulp-clean');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const minify = require('gulp-minify');
const es = require('event-stream');
const plumber = require('gulp-plumber');
const runSequence = require('run-sequence');
const watch = require('gulp-watch');
const browserSync = require('browser-sync').create();
const reload = browserSync.reload;
const fs = require('fs');
const pkgJson = JSON.parse(fs.readFileSync('./package.json'));
const ghPages = require('gulp-gh-pages');
gulp.task('deploy', function() {
return gulp.src('./example/**/*')
.pipe(ghPages());
});
const src = {
js: './src/**/*.js',
html: './example**/*.html',
css: './example**/*.css'
};
// Browser Sync - Static server
gulp.task('browser-sync', function() {
browserSync.init({
server: {
baseDir: "./example",
middleware: function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
next();
}
}
});
gulp.watch(src.html).on('change', reload);
gulp.watch(src.css).on('change', reload);
gulp.watch(src.js).on('change', reload);
});
// Clean Dist Dir
gulp.task('clean', function () {
return gulp.src('dist/')
.pipe(clean());
});
// - JavaScript Hint (Standard Codding)
gulp.task('jshint', function () {
return watch('./src/**/*.js', function () {
gulp.src('./src/**/*.js')
.pipe(plumber())
.pipe(jshint('./.jshintrc'))
.pipe(jshint.reporter('jshint-stylish'));
});
});
// - JavaScript Uflify Task
gulp.task('uglify', function () {
return watch('./src/**/*.js', function () {
es.merge([
gulp.src(['src/**/*.js']).pipe(concat('scripts.js'))
])
.pipe(concat( pkgJson.name + '.js'))
.pipe(plumber())
.pipe(minify({
ext:{
src:'.js',
min:'.min.js'
},
exclude: ['tasks'],
ignoreFiles: ['.combo.js', '-min.js']
}))
.pipe(gulp.dest('./example/js'))
.pipe(gulp.dest('./dist/js'));
browserSync.reload
});
});
// Rerun the task when a file changes
gulp.task('watch', function() {
gulp.watch( './js/**/*.js' , ['jshint', 'uglify']);
});
gulp.task('default', function (cb) {
return runSequence('clean', ['jshint', 'uglify', 'browser-sync'], cb)
});