-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgulpfile.js
executable file
·93 lines (81 loc) · 2.76 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
// Defining requirements
var gulp = require( 'gulp' );
var plumber = require( 'gulp-plumber' );
var sass = require( 'gulp-sass' );
var watch = require( 'gulp-watch' );
var log = require('fancy-log');
var beeper = require('beeper');
var colors = require('ansi-colors');
var notify = require('gulp-notify');
var rename = require( 'gulp-rename' );
var uglify = require( 'gulp-uglify' );
var sourcemaps = require( 'gulp-sourcemaps' );
var browserSync = require( 'browser-sync' ).create();
var del = require( 'del' );
var cleanCSS = require( 'gulp-clean-css' );
var gulpSequence = require( 'gulp-sequence' );
var autoprefixer = require( 'gulp-autoprefixer' );
var buffer = require('gulp-buffer');
var debug = require('gulp-debug');
// Configuration file to keep your code DRY
var cfg = require( './gulpconfig.json' );
var paths = cfg.paths;
// Run:
// gulp sass
// Compiles SCSS files in CSS
gulp.task('sass', function() {
var stream = gulp.src(paths.sass + '/*.scss')
.pipe( plumber(errorHandler))
.pipe( sourcemaps.init({ loadMaps: true }))
.pipe( sass({ errLogToConsole: true }))
.pipe( autoprefixer('last 2 versions'))
.pipe( sourcemaps.write(undefined, { sourceRoot: null }))
.pipe( gulp.dest(paths.css) );
return stream;
});
// Run:
// gulp watch
// Starts watcher. Watcher runs gulp sass task on changes
gulp.task( 'watch', function() {
//gulp.watch( paths.sass + '/**/*.scss', ['styles'] );
gulp.watch( [paths.src + '/*.js'], ['js'] );
});
// Run:
// gulp browser-sync
// Starts browser-sync task for starting the server.
gulp.task( 'browser-sync', function() {
browserSync.init( cfg.browserSyncWatchFiles, cfg.browserSyncOptions );
});
// Run:
// gulp watch-bs
// Starts watcher with browser-sync. Browser-sync reloads page automatically on your browser
gulp.task( 'watch-bs', ['browser-sync', 'watch', 'js'], function() {});
// Run:
// gulp scripts.
// Uglifies and concat all JS files into one
gulp.task( 'js', function() {
return gulp.src(paths.src + '/*.js') // no need of reading file because browserify does.
.pipe(plumber(errorHandler))
// transform streaming contents into buffer contents (because gulp-sourcemaps does not support streaming contents)
.pipe(buffer())
.pipe( uglify() )
.on('error', function (err) {
log(colors.red('[Error]'), err.toString());
})
.pipe( rename( { suffix: '.min' } ) )
.pipe(gulp.dest( paths.dist ))
.pipe( notify({message: 'JS task complete'}));
});
// Deleting any file inside the /src folder
gulp.task( 'clean-source', function() {
return del( ['src/**/*'] );
});
function errorHandler(error) {
log(error);
console.log(error);
// 3 beeps for error
beep();
beep();
beep();
return true;
}