-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.babel.js
More file actions
138 lines (119 loc) · 3.11 KB
/
gulpfile.babel.js
File metadata and controls
138 lines (119 loc) · 3.11 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
import gulp from 'gulp';
import concat from 'gulp-concat';
import sass from 'gulp-sass';
import ngAnnotate from 'gulp-ng-annotate';
import templateCache from 'gulp-angular-templatecache';
import server from 'browser-sync';
import sourcemaps from 'gulp-sourcemaps';
import uglify from 'gulp-uglify';
import clean from 'gulp-clean';
import sequence from 'run-sequence';
import child from 'child_process';
import configFn from './gulpfile.config';
// gulp config
var config = configFn();
var exec = child.exec;
server.create();
gulp.task('clean:templates', () => {
return gulp
.src(config.paths.dist + '/templates.js')
.pipe(clean());
})
gulp.task('clean:dist', () => {
return gulp
.src(config.paths.dist)
.pipe(clean());
})
gulp.task('templates', () => {
return gulp
.src(config.paths.templates)
.pipe(templateCache(config.templateCache))
.pipe(gulp.dest(config.paths.dist));
});
gulp.task('vendors', () => {
return gulp
// add node_modules path prefix
.src([...config.paths.vendors.map(i => `node_modules/${i}`),
...config.paths.libs
])
.pipe(concat('vendors.js'))
.pipe(gulp.dest(config.paths.dist));
});
gulp.task('vendors:prod', () => {
return gulp
// add node_modules path prefix
.src([...config.paths.vendorsProd.map(i => `node_modules/${i}`),
...config.paths.libs
])
.pipe(concat('vendors.js'))
.pipe(gulp.dest(config.paths.dist));
});
gulp.task('static', () => {
return gulp
.src(config.paths.static)
.pipe(gulp.dest(config.paths.dist));
});
gulp.task('scripts', ['templates'], () => {
return gulp
.src([
// load modules first
`${config.root}/**/*.module.js`,
`${config.paths.dist}/templates.js`,
...config.paths.scripts
])
.pipe(sourcemaps.init())
.pipe(concat('bundle.js'))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(config.paths.dist));
});
gulp.task('scripts:prod', ['templates'], () => {
return gulp
.src([
// load modules first
`${config.root}/**/*.module.js`,
`${config.paths.dist}/templates.js`,
...config.paths.scripts
])
.pipe(ngAnnotate())
.pipe(concat('bundle.js'))
.pipe(uglify())
.pipe(gulp.dest(config.paths.dist));
});
gulp.task('styles', () => {
return gulp
.src(config.paths.styles)
.pipe(sass())
.pipe(concat('styles.css'))
.pipe(gulp.dest(config.paths.dist))
.pipe(server.stream()); // make styles injected
});
gulp.task('serve', ['static', 'vendors', 'styles', 'scripts'], () => {
server.init({
server: {
baseDir: './dist'
},
stream: true
});
gulp.watch([config.paths.scripts, config.paths.templates], ['watch-scripts']);
gulp.watch([config.paths.styles], ['watch-styles']);
gulp.watch([config.paths.static], ['watch-static']);
});
gulp.task('deploy', cb => {
sequence('clean:dist', 'static', 'vendors:prod', 'styles', 'scripts:prod', 'clean:templates');
return exec('firebase deploy', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
})
gulp.task('watch-scripts', ['scripts'], (done) => {
server.reload();
done();
});
gulp.task('watch-styles', ['styles'], (done) => {
done();
});
gulp.task('watch-static', ['static'], (done) => {
server.reload();
done();
});