This repository has been archived by the owner on Oct 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
62 lines (57 loc) · 1.77 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
const gulp = require('gulp');
const $ = require('gulp-load-plugins')();
const uglify = require('gulp-uglify');
const sourcemaps = require('gulp-sourcemaps');
const plumber = require('gulp-plumber');
const notify = require('gulp-notify');
const eslint = require('gulp-eslint');
const header = require('gulp-header');
const browserSync = require('browser-sync').create();
gulp.task('lint', function() {
return gulp.src('source/browser-detect.js')
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('build', function() {
const pkg = require('./package.json');
const banner = [
'/**',
' * <%= pkg.description %> v<%= pkg.version %> | <%= pkg.license %>',
' * Author: <%= pkg.author %>',
' * <%= pkg.homepage %>',
' */',
''
].join('\n');
return gulp.src('source/browser-detect.js')
.pipe(plumber({
errorHandler: notify.onError('JS: <%= error.message %>')
}))
.pipe(sourcemaps.init())
.pipe(uglify())
.pipe($.rename('browser-detect.min.js'))
.pipe(header(banner, { pkg: pkg }))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('dist'))
.pipe(notify({
message: 'Compilation complete: <%= file.relative %>',
onLast: true
}));
});
gulp.task('browser-sync', function() {
browserSync.init({
server: {
baseDir: './test/',
directory: true,
routes: {
'/dist': './dist'
},
index: 'index.html'
},
files: ['dist/*.js', 'examples/*'],
open: false
});
});
gulp.task('default', ['lint', 'build', 'browser-sync'], function() {
gulp.watch('source/browser-detect.js', ['lint', 'build']);
});