-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
71 lines (61 loc) · 1.89 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
var fs = require('fs');
var gulp = require('gulp');
var pkg = require('./package.json');
gulp.util = require('gulp-util');
var config = {
scripts: ['*.js', 'lib/*.js', 'test/*.js']
};
config.lint = config.scripts.concat(['test/*.js']);
gulp.task('clear-dist-dir', function(){
fs.readdirSync('./dist').forEach( function( filename ){
fs.unlinkSync( './dist/' + filename );
});
});
gulp.task( 'build-dist', ['lint', 'clear-dist-dir'], function(){
return require('browserify')({
debug: true
})
.add('./index.js')
.bundle()
.pipe( fs.createWriteStream('./dist/:name.js'.replace(':name', pkg.name)) );
});
gulp.task( 'minify-dist', ['clear-dist-dir', 'build-dist'], function(){
return gulp.src('./dist/:name.js'.replace(':name', pkg.name))
.pipe( require('gulp-uglify')() )
.pipe( require('gulp-concat')(':name.min.js'.replace(':name', pkg.name)) )
.pipe( gulp.dest('./dist') );
});
gulp.task( 'scripts', function(){
return require('browserify')({
debug: true
})
.add('./test/public/js/app.js')
.bundle()
.pipe( fs.createWriteStream('./test/public/dist/app.js') );
});
gulp.task( 'lint', function(){
return gulp.src( config.lint )
.pipe( require('gulp-jshint')({
"laxcomma": true,
"sub": true,
"globals": {
"console": true,
"module": true
}
}))
.pipe( require('gulp-jshint').reporter('jshint-stylish') );
});
gulp.task( 'server', function(){
require('gulp-connect').server({
root: 'test/public'
, port: 3040
});
});
gulp.task( 'watch', function(){
gulp.watch( config.lint, ['lint'] );
gulp.watch( config.scripts, ['scripts'] );
gulp.watch( ['less/*.less', 'less/**/*.less'], ['less'] );
});
gulp.task( 'dist', [ 'lint', 'clear-dist-dir', 'build-dist', 'minify-dist' ] );
gulp.task( 'build', [ 'lint', 'scripts' ] );
gulp.task( 'default', [ 'build', 'server', 'watch' ] );