-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
executable file
·136 lines (115 loc) · 3.8 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
var gulp = require('gulp');
var gutil = require('gulp-util'),
jshint = require('gulp-jshint'),
browserify = require('gulp-browserify'),
/* concat = require('gulp-concat'), */
minifyCss = require('gulp-minify-css'),
copy = require('gulp-copy'),
plumber = require('gulp-plumber'),
uglify = require('gulp-uglify'),
sourcemaps = require('gulp-sourcemaps'),
rename = require('gulp-rename'),
source = require('vinyl-source-stream'),
watchify = require('watchify'),
buffer = require('vinyl-buffer'),
fastbrowserify = require('browserify'),
assign = require('lodash.assign'),
karma = require('gulp-karma');
gulp.task('test', function(){
// Be sure to return the stream
// NOTE: Using the fake './foobar' so as to run the files
// listed in karma.conf.js INSTEAD of what was passed to
// gulp.src !
return gulp.src('./foobar')
.pipe(karma({configFile: 'karma.conf.js',
action: 'run'}))
.on('error', function(err){
console.log(err);
this.emit('end');
});
});
gulp.task('autotest', function(){
return gulp.watch(['public/js/app/**/*.js', 'test/spec/*.js'], ['test'])
});
gulp.task('default', function() {
// place code for your default task here
});
gulp.task('lint', function(){
gulp.src(['public/js/app/components/**/*.js', 'public/js/app/shared/**/*.js', 'public/js/app/router.js', 'public/js/app/app.js'])
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
/*
copy:{
main:{
files:[
{expand: true,cwd: 'bower_components/bootstrap/dist/', src:'**', dest:'public/bootstrap/'}]
}
}
*/
gulp.task('copy', function(){
});
gulp.task('uglify', function(){
return gulp.src('public/js/app/app-bundle.js')
.pipe(uglify())
.pipe(rename({basename:'app.min'}))
.pipe(gulp.dest('public/js/app'));
});
gulp.task('minifycss', function(){
return gulp.src(['public/css/socialSample.css'])
.pipe(sourcemaps.init())
.pipe(minifyCss({keepBreaks:true}))
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest('public/css/'));
});
gulp.task('pro-scripts', function(){
gulp.src('public/js/app/app.js')
.pipe(browserify({
insertGlobals : true,
debug : false
}))
.pipe(uglify())
.pipe(rename({basename:'app.min'}))
.pipe(gulp.dest('public/js/app'));
});
gulp.task('dev-scripts', function(){
gulp.src('public/js/app/app.js')
.pipe(browserify({
insertGlobals : true
}))
.pipe(rename({suffix:'-bundle'}))
.pipe(gulp.dest('public/js/app/'));
});
gulp.task('develop', function(){
gulp.start('dev-scripts', 'minifycss');
});
gulp.task('production', function(){
gulp.start('pro-scripts', 'minifycss');
});
// add custom browserify options here
var customOpts = {
entries: ['./public/js/app/app.js'],
debug: false
};
var opts = assign({}, watchify.args, customOpts);
var b = watchify(fastbrowserify(opts));
// add transformations here
// i.e. b.transform(coffeeify);
gulp.task('js', bundle); // so you can run `gulp js` to build the file
b.on('update', bundle); // on any dep update, runs the bundler
b.on('log', gutil.log); // output build logs to terminal
function bundle() {
return b.bundle()
// log errors if they happen
.on('error', gutil.log.bind(gutil, 'Browserify Error'))
.pipe(source('app-bundle.js'))
// optional, remove if you don't need to buffer file contents
//.pipe(buffer())
// optional, remove if you dont want sourcemaps
//.pipe(sourcemaps.init({loadMaps: true})) // loads map from browserify file
// Add transformation tasks to the pipeline here.
//.pipe(sourcemaps.write('./')) // writes .map file
.pipe(gulp.dest('public/js/app/'));
}