-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
132 lines (118 loc) · 3.61 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
var gulp = require('gulp'),
debug = require('gulp-debug'),
nodemon = require('gulp-nodemon'),
loopbackAngular = require('gulp-loopback-sdk-angular'),
usemin = require('gulp-usemin'),
wrap = require('gulp-wrap'),
connect = require('gulp-connect'),
watch = require('gulp-watch'),
minifyCss = require('gulp-cssnano'),
minifyJs = require('gulp-uglify'),
sourcemaps = require('gulp-sourcemaps'),
concat = require('gulp-concat'),
less = require('gulp-less'),
rename = require('gulp-rename'),
minifyHTML = require('gulp-htmlmin');
var paths = {
server: 'server/**/*.{js,json}',
models: 'common/**/*.{js,json}',
scripts: 'client/src/js/**/*.*',
cssstyles: 'client/src/css/**/*.*',
styles: 'client/src/less/**/*.*',
images: 'client/src/img/**/*.*',
templates: 'client/src/templates/**/*.html',
index: 'client/src/index.html',
bower_fonts: 'client/src/components/**/*.{ttf,woff,woff2,eof,svg}'
};
/**
* Handle bower components from index
*/
gulp.task('usemin', function () {
return gulp.src(paths.index)
.pipe(usemin({
js: [minifyJs(), 'concat'],
css: [minifyCss({
keepSpecialComments: 0
}), 'concat'],
}))
.pipe(gulp.dest('client/dist/'));
});
/**
* Copy assets
*/
gulp.task('build-assets', ['copy-bower_fonts']);
gulp.task('copy-bower_fonts', function () {
return gulp.src(paths.bower_fonts)
.pipe(rename({
dirname: '/fonts'
}))
.pipe(gulp.dest('client/dist/lib'));
});
/**
* Handle custom files
*/
gulp.task('build-custom', ['custom-images', 'custom-js', 'custom-less', 'custom-templates']);
gulp.task('custom-images', function () {
return gulp.src(paths.images)
.pipe(gulp.dest('client/dist/img'));
});
gulp.task('custom-js', function () {
return gulp.src(paths.scripts)
.pipe(sourcemaps.init())
.pipe(debug())
.pipe(minifyJs())
.pipe(concat('dashboard.min.js'))
.pipe(sourcemaps.write('../maps'))
.pipe(gulp.dest('client/dist/js'));
});
gulp.task('custom-less', function () {
return gulp.src(paths.styles)
.pipe(less())
.pipe(gulp.dest('client/dist/css'));
});
gulp.task('custom-templates', function () {
return gulp.src(paths.templates)
.pipe(minifyHTML())
.pipe(gulp.dest('client/dist/templates'));
});
/**
* auto-generate angular $resource handlers from LoopBack services
**/
gulp.task('build-strongloop-angular', function () {
return gulp.src('./server/server.js')
.pipe(loopbackAngular())
.pipe(rename('lb-services.js'))
.pipe(gulp.dest('./client/dist/js'));
;
});
/**
* Watch custom files
*/
gulp.task('watch', function () {
gulp.watch([paths.models], ['build-strongloop-angular']);
gulp.watch([paths.server], ['build-strongloop-angular']);
gulp.watch([paths.images], ['custom-images']);
gulp.watch([paths.cssstyles], ['usemin']);
gulp.watch([paths.styles], ['custom-less']);
gulp.watch([paths.scripts], ['custom-js']);
gulp.watch([paths.templates], ['custom-templates']);
gulp.watch([paths.index], ['usemin']);
});
gulp.task('start', function () {
nodemon({
script: 'server/server.js',
ext: 'js json html',
env: {
'NODE_ENV': 'development'
}
})
.on('restart', function () {
console.log('restarted!')
})
});
/**
* Gulp tasks
*/
gulp.task('build', ['usemin', 'build-assets', 'build-custom',
'build-strongloop-angular']);
gulp.task('default', ['build', 'start', 'watch']);