-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
196 lines (168 loc) · 4.43 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
const { readFileSync } = require('fs'),
{ series, parallel, src, dest, watch } = require('gulp'),
angularTemplatecache = require('gulp-angular-templatecache'),
cleanCss = require('gulp-clean-css'),
concat = require('gulp-concat'),
connect = require('gulp-connect'),
del = require('del'),
footer = require('gulp-footer'),
gulpIf = require('gulp-if'),
header = require('gulp-header'),
ngAnnotate = require('gulp-ng-annotate-patched'),
rev = require('gulp-rev'),
revRewrite = require('gulp-rev-rewrite'),
sass = require('gulp-sass')(require('sass')),
shell = require('gulp-shell'),
uglify = require('gulp-uglify');
const scripts = [
'node_modules/angular/angular.js',
'node_modules/angular-*/*.js',
'!node_modules/angular*/*.min.js',
'!node_modules/angular*/*-mocks.js',
'!node_modules/angular*/index.js',
'!node_modules/angular-mocks/*.js',
'app/**/*.module.js',
'app/app.module.js',
'app/index.js',
'app/**/*.js',
'!app/**/*.spec.js',
'!app/app.min.js'
];
const styles = [
'app/index.scss',
'app/**/*.scss'
], styleIncludes = [
'node_modules/angular-material'
];
function is_src(file) {
return !/node_modules/.test(file.path);
}
/* Development *///////////////////////////////////////////
function js() {
return src(scripts, { sourcemaps: true })
.pipe(gulpIf(is_src, header('(function() { "use strict";\n')))
.pipe(gulpIf(is_src, footer('\n})();')))
.pipe(concat('app.min.js'))
.pipe(ngAnnotate({add: true}))
.pipe(dest('app', { sourcemaps: '.' }));
}
function css() {
return src(styles, { sourcemaps: true })
.pipe(concat('app.min.scss'))
.pipe(sass({ includePaths: styleIncludes }).on('error', sass.logError))
.pipe(dest('app', { sourcemaps: '.' }));
}
function serve(done) {
connect.server({
root: 'app/',
port: 8888,
fallback: 'app/index.html',
livereload: true
}, done);
}
function reload(path) {
return src(path)
.pipe(connect.reload());
}
function reload_js() {
return reload('app/app.min.js');
}
function reload_css() {
return reload('app/app.min.css');
}
function watch_src(done) {
watch(['app/**/*.html'])
.on('all', (event, path) => reload(path));
watch(scripts, series(js, reload_js));
watch(styles, series(css, reload_css));
done();
}
exports.default = series(
parallel(js, css),
parallel(serve, watch_src)
);
/* Distribution *//////////////////////////////////////////
function dist_clean() {
return del(['dist/**/*']);
}
const templates = [
'app/**/*.html',
'!app/index.html'
];
function partials() {
return src(templates)
.pipe(angularTemplatecache('templates.js', {
transformUrl: function(url) {
// Remove leading slash which occurs in gulp 4
return url.replace(/^\/+/g, '');
}
}))
.pipe(dest('dist'));
}
function dist_js_build() {
return src(scripts.concat(['dist/templates.js']), { sourcemaps: true })
.pipe(gulpIf(is_src, header('(function() { "use strict";\n')))
.pipe(gulpIf(is_src, footer('\n})();')))
.pipe(concat('app.min.js'))
.pipe(ngAnnotate({add: true}))
.pipe(uglify())
.pipe(dest('dist', { sourcemaps: '.' }));
}
function dist_js() {
return del(['dist/templates.js']);
}
function dist_css() {
return src(styles, { sourcemaps: true })
.pipe(concat('app.min.scss'))
.pipe(sass({ includePaths: styleIncludes }).on('error', sass.logError))
.pipe(cleanCss())
.pipe(dest('dist', { sourcemaps: '.' }));
}
function revision() {
return src(['dist/app.min.css', 'dist/app.min.js'])
.pipe(rev())
.pipe(dest('dist'))
.pipe(rev.manifest())
.pipe(dest('dist'));
}
function dist_index() {
const manifest = readFileSync('dist/rev-manifest.json');
return src('app/index.html')
.pipe(revRewrite({ manifest }))
.pipe(dest('dist'));
}
function dist_app() {
return del(['dist/app.min.css', 'dist/app.min.js', 'dist/rev-manifest.json']);
}
function dist_favicon() {
return src('app/favicon.png')
.pipe(dest('dist'));
}
function dist_images() {
return src('app/images/**/*.*')
.pipe(dest('dist/images'));
}
exports.build = series(
dist_clean,
parallel(
series(
parallel(
series(partials, dist_js_build, dist_js),
dist_css
),
revision,
dist_index,
dist_app
),
dist_favicon,
dist_images
)
);
function dist_serve(done) {
connect.server({
root: 'dist/',
port: 8888,
fallback: 'dist/index.html'
}, done);
}
exports.dist_serve = dist_serve;