-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
85 lines (72 loc) · 1.91 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
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 configFn from './gulpfile.config';
// gulp config
var config = configFn();
server.create();
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}`))
.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('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('watch-scripts', ['scripts'], (done) => {
server.reload();
done();
});
gulp.task('watch-styles', ['styles'], (done) => {
done();
});
gulp.task('watch-static', ['static'], (done)=>{
server.reload();
done();
})