-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
49 lines (44 loc) · 1.4 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
'use strict';
var gulp = require('gulp');
var concat = require('gulp-concat');
var gutil = require('gulp-util');
var jshint = require('gulp-jshint');
var uglify = require('gulp-uglify');
var uglifySaveLicense = require('uglify-save-license');
var rename = require('gulp-rename');
var sourcemaps = require('gulp-sourcemaps');
var wrap = require('gulp-wrap');
var options = {
src: './src',
dist: './dist',
errorHandler: function(title) {
return function(err) {
gutil.log(gutil.colors.red('[' + title + ']'), err.toString());
this.emit('end');
};
}
};
gulp.task('js', function () {
return gulp.src([
options.src + '/menu.js',
options.src + '/extend.js',
options.src + '/menu-item.js',
options.src + '/exports.js'
])
.pipe(concat('menu.js'))
.pipe(wrap('(function(global){\n\'use strict\';\n <%= contents %>\n})(this);'))
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('jshint-stylish'))
.pipe(gulp.dest(options.dist))
.pipe(sourcemaps.init())
.pipe(uglify({ preserveComments: uglifySaveLicense, enclose: true })).on('error', options.errorHandler('Uglify'))
.pipe(sourcemaps.write())
.pipe(rename({
extname: '.min.js'
}))
.pipe(gulp.dest(options.dist));
});
gulp.task('default', ['css', 'js']);
gulp.task('watch', function () {
gulp.watch(options.src + '/*.js', ['js']);
});