This repository has been archived by the owner on Jul 3, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
/
gulpfile.js
84 lines (70 loc) · 2.06 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
'use strict';
var gulp = require('gulp'),
gutil = require('gulp-util'),
plumber = require('gulp-plumber'),
notifier = require('node-notifier'),
uglify = require('gulp-uglify'),
concat = require('gulp-concat'),
stripDebug = require('gulp-strip-debug'),
browserSync = require('browser-sync'),
reload = browserSync.reload,
project = require('./package.json');
var paths = {
src: './src/**/*.js',
dist: '.dist/',
vendor: './vendor/**/*.js',
output: './dist'
};
gulp.task('build:unbundled', function() {
return gulp.src(paths.src)
.pipe(plumber({errorHandler: function (err) {
gutil.log(
gutil.colors.red("js compile error:"),
err.message
);
notifier.notify({ title: 'Error in Task "build:unbundled"', message: err.message });
}}))
.pipe(uglify())
.pipe(gulp.dest(paths.output));
});
gulp.task('build:bundled', function() {
return gulp.src([ paths.vendor, paths.src ])
.pipe(plumber({errorHandler: function (err) {
gutil.log(
gutil.colors.red("Sass compile error:"),
err.message
);
notifier.notify({ title: 'Error in Task "build:bundled"', message: err.message });
}}))
.pipe(concat(project.name + '.bundled.js'))
.pipe(uglify())
.pipe(gulp.dest(paths.output))
.pipe(reload({stream: true}));
});
gulp.task('watch', function () {
gulp.watch('demo/*').on('change', function () {
reload();
});
gulp.watch('src/*.js', ['build']);
});
gulp.task('browser-sync', function () {
return browserSync.init({
open: true,
port: 3005,
startPath: 'index.html',
notify: false,
server: {
baseDir: ['.', 'demo']
}
});
});
gulp.task('dist', ['build'], function () {
return gulp.src(paths.output+'/**/*.js')
.pipe(stripDebug())
.pipe(gulp.dest(paths.output));
});
// build: generates uglified version
// and adds vendor scripts polyfill & smoothscroll
gulp.task('build', [ 'build:bundled', 'build:unbundled' ]);
// assign default gulp task
gulp.task('default', [ 'browser-sync', 'build', 'watch']);