-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgulpfile.js
More file actions
189 lines (168 loc) · 4.78 KB
/
gulpfile.js
File metadata and controls
189 lines (168 loc) · 4.78 KB
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*********************************
Dependencies
*********************************/
// Node dependencies
var gulp = require('gulp');
// Gulp dependencies
var annotate = require('gulp-ng-annotate');
var babel = require('gulp-babel');
var concat = require('gulp-concat');
var minify = require('gulp-cssnano');
var notify = require('gulp-notify');
var plumber = require('gulp-plumber');
var prefix = require('gulp-autoprefixer');
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var templates = require('gulp-angular-templatecache');
var uglify = require('gulp-uglify');
// Define directories
var nodePath = './node_modules/';
var publicPath = './public/';
var resPath = './assets/';
/*********************************
Variables
*********************************/
// Define error handler
var reportError = function (error) {
notify({
title: 'Gulp Task Error',
message: '<%= error.message %>',
});
console.log(error.toString());
this.emit('end');
};
// Files and paths to be watched by Gulp
var watchPaths = {
angular: [
resPath + 'scripts/angular/**/*.js',
resPath + 'scripts/angular/**/**/*.html',
resPath + 'scripts/angular/**/**/*.js',
resPath + 'scripts/angular/**/**/*.component.js',
resPath + 'scripts/angular/**/*.html',
],
sass: [
resPath + 'styles/*.scss',
resPath + 'styles/**/*.scss',
],
scripts: [
resPath + 'scripts/*.js',
resPath + 'scripts/*/**.js',
],
};
/*********************************
Tasks
*********************************/
// Task for Angular
gulp.task('angular', () => {
'use strict';
gulp.src([
resPath + 'scripts/angular/app/*.js',
resPath + 'scripts/angular/components/**/*.js',
resPath + 'scripts/angular/components/**/*.component.js',
resPath + 'scripts/angular/components/**/*.tpl.js',
resPath + 'scripts/angular/routes/*.js',
resPath + 'scripts/angular/services/*.js',
])
.pipe(plumber({
errorHandler: reportError,
}))
.pipe(sourcemaps.init())
.pipe(babel({
presets: ['es2015'],
}))
.pipe(concat('app.js'))
.pipe(annotate())
.pipe(uglify({
mangle: {
except: ['angular'],
},
}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(publicPath + 'scripts'));
});
// Task for Node-installed libraries
gulp.task('modules', () => {
'use strict';
gulp.src([
nodePath + 'angular/angular.min.js',
nodePath + 'angular-sanitize/angular-sanitize.min.js',
nodePath + 'angular-ui-router/release/angular-ui-router.min.js',
nodePath + 'angular-ui-bootstrap/dist/ui-bootstrap.js',
nodePath + 'angular-ui-bootstrap/dist/ui-bootstrap-tpls.js',
nodePath + 'jquery/dist/jquery.min.js',
nodePath + 'tether/dist/js/tether.min.js',
nodePath + 'bootstrap/dist/js/bootstrap.min.js',
nodePath + 'moment/moment.js',
nodePath + 'angular-moment/angular-moment.min.js',
nodePath + 'underscore/underscore-min.js',
nodePath + 'angular-underscore/index.js',
])
.pipe(plumber({
errorHandler: reportError,
}))
.pipe(sourcemaps.init())
.pipe(concat('libraries.js'))
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(publicPath + 'scripts'));
});
// Task for Sass stylesheets
gulp.task('sass', () => {
'use strict';
gulp.src(resPath + 'styles/main.scss')
.pipe(plumber({
errorHandler: reportError,
}))
.pipe(sourcemaps.init())
.pipe(sass({
includePaths: [
'./assets/styles/',
'./node_modules/',
],
}))
.pipe(prefix())
.pipe(minify())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(publicPath + 'styles'));
});
// Task for JavaScript files
gulp.task('scripts', () => {
'use strict';
gulp.src(resPath + 'scripts/app.js')
.pipe(plumber({
errorHandler: reportError,
}))
.pipe(sourcemaps.init())
.pipe(babel({
presets: ['es2015'],
}))
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(publicPath + 'scripts'));
});
// Task for Angular templates
gulp.task('templates', () => {
'use strict';
gulp.src([
resPath + 'scripts/angular/components/**/*.html',
])
.pipe(templates('templates.js', {
standalone: true,
}))
.pipe(gulp.dest(publicPath + 'ng-templates'));
});
/*********************************
Watchers
*********************************/
// Watch task
gulp.task('watch', () => {
// Use: .watch(watchPaths.array, ['task']);
gulp.watch(watchPaths.angular, ['angular', 'templates']);
gulp.watch(watchPaths.sass, ['sass']);
gulp.watch(watchPaths.scripts, ['scripts']);
});
/*********************************
Entry Point
*********************************/
// Default task
gulp.task('default', ['angular', 'sass', 'scripts', 'templates', 'watch']);