-
Notifications
You must be signed in to change notification settings - Fork 230
/
Copy pathgulpfile.js
82 lines (75 loc) · 2.31 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
'use strict';
var gulp = require('gulp');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var mochaPhantomJS = require('gulp-mocha-phantomjs');
var browserSync = require('browser-sync');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var header = require('gulp-header');
var config = {
src: 'src',
dist: 'dist',
build: '',
test: 'test',
};
var pkg = require('./package.json');
gulp.task('browserify', function() {
return browserify('./' + config.src + '/index.js')
.bundle()
.on('error', function(err) {
console.log(err.toString());
this.emit('end');
})
.pipe(source(pkg.name + '.js'))
.pipe(gulp.dest(config.dist))
.pipe(browserSync.reload({stream:true}));
});
gulp.task('browserify-tests', function() {
return browserify('./' + config.test + '/tests.js')
.bundle()
.on('error', function(err) {
console.log(err.toString());
this.emit('end');
})
.pipe(source(pkg.name + '-tests.js'))
.pipe(gulp.dest(config.dist))
.pipe(browserSync.reload({stream:true}));
});
gulp.task('browser-sync', function() {
browserSync({
server: {
baseDir: ['./' + config.test + '/browser/', './'],
},
});
});
gulp.task('serve-test', ['browserify', 'browserify-tests'], function() {
gulp.start('browser-sync');
gulp.watch(config.test + '/*.js', ['browserify', 'browserify-tests']);
gulp.watch(config.src + '/**/*.js', ['browserify', 'browserify-tests']);
});
gulp.task('build', ['browserify'], function() {
var headerText =
'/*\n' +
' * QueryLoader2 - A simple script to create a preloader for images\n' +
' *\n' +
' * For instructions read the original post:\n' +
' * http://www.gayadesign.com/diy/queryloader2-preload-your-images-with-ease/\n' +
' *\n' +
' * Copyright (c) 2011 - Gaya Kessler\n' +
' *\n' +
' * Licensed under the MIT license:\n' +
' * http://www.opensource.org/licenses/mit-license.php\n' +
' *\n' +
' * Version: <%= version %>\n' +
' * Last update: <%= date %>\n' +
' */\n';
gulp.src(config.dist + '/' + pkg.name + '.js')
.pipe(uglify())
.pipe(rename(pkg.name + '.min.js'))
.pipe(header(headerText, {
version: pkg.version,
date: new Date().toJSON().slice(0, 10),
}))
.pipe(gulp.dest(config.build));
});