1
|
1 |
var gulp = require('gulp'); |
|
2 |
var gutil = require('gulp-util') |
|
3 |
var plugins = require("gulp-load-plugins")({lazy:false}); |
|
4 |
//var flatten = require('gulp-flatten'); |
|
5 |
//var uglify = require('gulp-uglify'); |
|
6 |
//var clean = require('gulp-clean'); |
|
7 |
//var rename = require('gulp-rename'); |
|
8 |
//var filesize = require('gulp-filesize'); |
|
9 |
//var cssmin = require('gulp-cssmin'); |
|
10 |
|
|
11 |
gulp.task('clean', function () { |
|
12 |
return gulp.src('build', {read: false}) |
|
13 |
.pipe(clean()); |
|
14 |
}); |
|
15 |
|
|
16 |
var scriptsSrc = ['!./app/**/*_test.js','./app/**/*.js']; |
|
17 |
|
|
18 |
gulp.task('scripts', function(){ |
|
19 |
//combine all js files of the app |
|
20 |
gulp.src(scriptsSrc) |
|
21 |
.pipe(plugins.jshint()) |
|
22 |
.pipe(plugins.jshint.reporter('default')) |
|
23 |
.pipe(plugins.jshint.reporter('fail')) |
|
24 |
.pipe(plugins.concat('app.js')) |
|
25 |
.pipe(gulp.dest('./build')) |
|
26 |
.pipe(plugins.filesize()) |
|
27 |
.pipe(plugins.uglify()) |
|
28 |
.pipe(plugins.rename('app.min.js')) |
|
29 |
.pipe(gulp.dest('./build')) |
|
30 |
.pipe(plugins.filesize()) |
|
31 |
.on('error', gutil.log); |
|
32 |
}); |
|
33 |
|
|
34 |
gulp.task('templates',function(){ |
|
35 |
//combine all template files of the app into a js file |
|
36 |
gulp.src(['!./app/index.html', |
|
37 |
'./app/**/*.html']) |
|
38 |
.pipe(plugins.angularTemplatecache('templates.js',{standalone:true})) |
|
39 |
.pipe(gulp.dest('./build')); |
|
40 |
}); |
|
41 |
|
|
42 |
gulp.task('css', function(){ |
|
43 |
gulp.src('./app/**/*.css') |
|
44 |
// .pipe(plugins.csslint()) |
|
45 |
// .pipe(plugins.csslint.reporter()) |
|
46 |
.pipe(plugins.concat('app.css')) |
|
47 |
.pipe(gulp.dest('./build')) |
|
48 |
.pipe(plugins.filesize()) |
|
49 |
.pipe(plugins.minifyCss({keepBreaks:true})) |
|
50 |
.pipe(plugins.rename('app.min.css')) |
|
51 |
.pipe(gulp.dest('./build')) |
|
52 |
.pipe(plugins.filesize()); |
|
53 |
}); |
|
54 |
|
|
55 |
var vendorJSsrc = [ |
|
56 |
'!./bower_components/**/*.min.js', |
|
57 |
'!./bower_components/bootstrap/Gruntfile.js', |
|
58 |
'!./bower_components/bootstrap/grunt/*', |
|
59 |
'!./bower_components/bootstrap/js/*', |
|
60 |
'!./bower_components/jquery/src/**/*', |
|
61 |
'!./bower_components/angular-bootstrap/ui-bootstrap.js', |
|
62 |
'./bower_components/jquery/dist/jquery.js', |
|
63 |
'./bower_components/**/*.js' |
|
64 |
]; |
|
65 |
|
|
66 |
gulp.task('vendorJS', function(){ |
|
67 |
//concatenate vendor JS files |
|
68 |
gulp.src(vendorJSsrc) |
|
69 |
.pipe(plugins.concat('lib.js')) |
|
70 |
.pipe(gulp.dest('./build')) |
|
71 |
.pipe(plugins.filesize()) |
|
72 |
.pipe(plugins.uglify()) |
|
73 |
.pipe(plugins.rename('lib.min.js')) |
|
74 |
.pipe(gulp.dest('./build')) |
|
75 |
.pipe(plugins.filesize()) |
|
76 |
.on('error', gutil.log); |
|
77 |
}); |
|
78 |
|
|
79 |
gulp.task('vendorCSS', function(){ |
|
80 |
//concatenate vendor CSS files |
|
81 |
gulp.src(['!./bower_components/**/*.min.css', |
|
82 |
'./bower_components/**/*.css']) |
|
83 |
.pipe(plugins.concat('lib.css')) |
|
84 |
.pipe(gulp.dest('./build')) |
|
85 |
.pipe(plugins.filesize()) |
|
86 |
.pipe(plugins.minifyCss({keepBreaks:true})) |
|
87 |
.pipe(plugins.rename('lib.min.css')) |
|
88 |
.pipe(gulp.dest('./build')) |
|
89 |
.pipe(plugins.filesize()); |
|
90 |
}); |
|
91 |
|
|
92 |
gulp.task('vendorFonts', function(){ |
|
93 |
gulp.src(['./bower_components/**/fonts/*']) |
|
94 |
.pipe(plugins.flatten()) |
|
95 |
.pipe(gulp.dest('./build/fonts')); |
|
96 |
}); |
|
97 |
|
|
98 |
gulp.task('copy-index', function() { |
|
99 |
gulp.src('./app/index.html') |
|
100 |
.pipe(gulp.dest('./build')); |
|
101 |
}); |
|
102 |
|
|
103 |
gulp.task('copy-data', function() { |
|
104 |
gulp.src('./data/**/*') |
|
105 |
.pipe(gulp.dest('./build/data')); |
|
106 |
}); |
|
107 |
|
|
108 |
gulp.task('copy-img', function() { |
|
109 |
gulp.src('./img/**/*') |
|
110 |
.pipe(gulp.dest('./build/img')); |
|
111 |
}); |
|
112 |
|
|
113 |
gulp.task('watch',function(){ |
|
114 |
gulp.watch([ |
|
115 |
'build/**/*.html', |
|
116 |
'build/**/*.js', |
|
117 |
'build/**/*.css' |
|
118 |
], function(event) { |
|
119 |
return gulp.src(event.path) |
|
120 |
.pipe(plugins.connect.reload()); |
|
121 |
}); |
|
122 |
gulp.watch(['./app/**/*.js','!./app/**/*test.js'],['scripts']); |
|
123 |
gulp.watch(['!./app/index.html','./app/**/*.html'],['templates']); |
|
124 |
gulp.watch('./app/**/*.css',['css']); |
|
125 |
gulp.watch('./app/index.html',['copy-index']); |
|
126 |
gulp.watch('./data/**/*',['copy-data']); |
|
127 |
gulp.watch('./img/**/*',['copy-img']); |
|
128 |
|
|
129 |
}); |
|
130 |
|
|
131 |
gulp.task('connect', plugins.connect.server({ |
|
132 |
root: ['build'], |
|
133 |
port: 9000, |
|
134 |
livereload: true |
|
135 |
})); |
|
136 |
|
|
137 |
gulp.task('default',['connect','scripts','templates','css','copy-index','copy-data','copy-img','vendorJS','vendorCSS','vendorFonts','watch']); |