-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
168 lines (141 loc) · 4.3 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
//Gulp.js configuration
//include gulp and plugins
var gulp = require('gulp'),
newer = require('gulp-newer'),
sourcestream = require('vinyl-source-stream'),
browserify = require('browserify'),
preprocess = require('gulp-preprocess'),
htmlclean = require('gulp-htmlclean'),
templateCache = require('gulp-angular-templatecache'),
imagemin = require('gulp-imagemin'),
imacss = require('gulp-imacss'),
del = require('del'),
less = require('gulp-less'),
pleeease = require('gulp-pleeease'),
jshint = require('gulp-jshint'),
mainBowerFiles = require('gulp-main-bower-files'),
concat = require('gulp-concat'),
pkg = require('./package.json');
//file locations
var
devBuild = ((process.env.NODE_ENV || 'development').trim().toLowerCase() !== 'production');
source = 'app_client/source/',
dest = 'app_client/build/',
html = {
in: source + '*.html',
watch: [source + 'index.html', source + 'templates/**/*.html'],
out: dest,
context: {
devBuild: devBuild
},
angularViews: {
in: source + 'app/**/*.html',
out: dest + 'js/',
options: {
filename: 'angularviews.js',
module: 'lavishMe'
}
}
},
images = {
in: source + 'images/*.*',
out: dest + 'images/'
},
imguri = {
in: source + 'less/inline_images/*',
out: source + 'less/images/',
filename: '_datauri.less',
namespace: 'img'
},
css = {
in: source + 'less/main.less',
watch: [source + 'less/**/*', '!' + imguri.out + imguri.filename],
out: dest + 'css/',
pleeeaseOpts: {
autoprefixer: { browsers: ['last 2 versions', '> 2%']},
rem: ['16px'],
pseudoElements: true,
mqpacker: true,
minifier: !devBuild
}
},
js = {
in: source + 'app/**/*.js',
out: dest + 'js/',
filename: 'main.js',
appStartFile: source + 'app/app.js'
};
//show build type
console.log(pkg.name + ' ' + pkg.version + ', '
+ (devBuild ? 'development' : 'production') + ' build');
//clean the build folder
gulp.task('clean', function() {
del([
dest + '*'
]);
});
//compile Less
gulp.task('less', ['imguri'], function() {
var page = gulp.src(css.in);
page = page.pipe(less());
page = page.pipe(pleeease(css.pleeeaseOpts));
return page.pipe(gulp.dest(css.out))
});
//build HTML files
gulp.task('html', function() {
var page = gulp.src(html.in).pipe(preprocess({context: html.context}));
if(!devBuild){
page = page.pipe(htmlclean());
}
return page.pipe(gulp.dest(html.out));
});
// manage images
gulp.task('images', function() {
return gulp.src(images.in)
.pipe(newer(images.out))
.pipe(imagemin())
.pipe(gulp.dest(images.out));
});
gulp.task('imguri', function() {
return gulp.src(imguri.in)
.pipe(imagemin())
.pipe(imacss(imguri.filename, imguri.namespace))
.pipe(gulp.dest(imguri.out));
});
gulp.task('js', function() {
if(devBuild) {
gulp.src(js.in)
.pipe(newer(js.out))
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'));
}
var bundleStream = browserify(js.appStartFile)
.bundle()
.pipe(sourcestream('main.js'));
return bundleStream.pipe(gulp.dest(js.out));
});
gulp.task('angularviews', function () {
return gulp.src(html.angularViews.in)
.pipe(templateCache(html.angularViews.options))
.pipe(gulp.dest(html.angularViews.out));
});
gulp.task('bower', function () {
return gulp.src('./bower.json')
.pipe(mainBowerFiles())
.pipe(concat('libs.js'))
.pipe(gulp.dest(js.out));
});
// default task
gulp.task('default', ['html', 'images', 'less', 'js', 'angularviews', 'bower'], function() {
//image changes
gulp.watch(images.in, ['images']);
//html changes
gulp.watch(html.watch, ['html']);
//Angular Views changes
gulp.watch(html.angularViews.in, ['angularviews']);
//css changes
gulp.watch([css.watch, imguri.in], ['less']);
//JS changes
gulp.watch([js.in], ['js']);
});