-
Notifications
You must be signed in to change notification settings - Fork 141
/
gulpfile.babel.js
125 lines (112 loc) · 3.06 KB
/
gulpfile.babel.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
import gulp from 'gulp';
import concat from 'gulp-concat';
import wrap from 'gulp-wrap';
import uglify from 'gulp-uglify';
import htmlmin from 'gulp-htmlmin';
import gulpif from 'gulp-if';
import sass from 'gulp-sass';
import yargs from 'yargs';
import ngAnnotate from 'gulp-ng-annotate';
import templateCache from 'gulp-angular-templatecache';
import server from 'browser-sync';
import del from 'del';
import path from 'path';
import child from 'child_process';
import sourcemaps from 'gulp-sourcemaps';
const exec = child.exec;
const argv = yargs.argv;
const root = 'src/';
const paths = {
dist: './dist/',
scripts: [`${root}/app/**/*.js`, `!${root}/app/**/*.spec.js`],
tests: `${root}/app/**/*.spec.js`,
styles: `${root}/sass/*.scss`,
templates: `${root}/app/**/*.html`,
modules: [
'angular/angular.js',
'angular-ui-router/release/angular-ui-router.js',
'firebase/firebase.js',
'angularfire/dist/angularfire.js',
'angular-loading-bar/build/loading-bar.min.js'
],
static: [
`${root}/index.html`,
`${root}/fonts/**/*`,
`${root}/img/**/*`
]
};
server.create();
gulp.task('clean', cb => del(paths.dist + '**/*', cb));
gulp.task('templates', () => {
return gulp.src(paths.templates)
.pipe(htmlmin({ collapseWhitespace: true }))
.pipe(templateCache({
root: 'app',
standalone: true,
transformUrl: function (url) {
return url.replace(path.dirname(url), '.');
}
}))
.pipe(gulp.dest('./'));
});
gulp.task('modules', ['templates'], () => {
return gulp.src(paths.modules.map(item => 'node_modules/' + item))
.pipe(concat('vendor.js'))
.pipe(gulpif(argv.deploy, uglify()))
.pipe(gulp.dest(paths.dist + 'js/'));
});
gulp.task('styles', () => {
return gulp.src(paths.styles)
.pipe(sass({outputStyle: 'compressed'}))
.pipe(gulp.dest(paths.dist + 'css/'));
});
gulp.task('scripts', ['modules'], () => {
return gulp.src([
`!${root}/app/**/*.spec.js`,
`${root}/app/**/*.module.js`,
...paths.scripts,
'./templates.js'
])
.pipe(sourcemaps.init())
.pipe(wrap('(function(angular){\n\'use strict\';\n<%= contents %>})(window.angular);'))
.pipe(concat('bundle.js'))
.pipe(ngAnnotate())
.pipe(gulpif(argv.deploy, uglify()))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(paths.dist + 'js/'));
});
gulp.task('serve', () => {
return server.init({
files: [`${paths.dist}/**`],
port: 4000,
server: {
baseDir: paths.dist
}
});
});
gulp.task('copy', ['clean'], () => {
return gulp.src(paths.static, { base: 'src' })
.pipe(gulp.dest(paths.dist));
});
gulp.task('watch', ['serve', 'scripts'], () => {
gulp.watch([paths.scripts, paths.templates], ['scripts']);
gulp.watch(paths.styles, ['styles']);
});
gulp.task('firebase', ['styles', 'scripts'], cb => {
return exec('firebase deploy', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
gulp.task('default', [
'copy',
'styles',
'serve',
'watch'
]);
gulp.task('production', [
'copy',
'scripts',
'firebase'
]);