-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfileserver.babel.js
95 lines (81 loc) · 2.77 KB
/
gulpfileserver.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
'use strict';
import gulp from 'gulp';
import del from 'del';
import source from 'vinyl-source-stream';
import buffer from 'vinyl-buffer';
import browserify from 'browserify';
import babelify from 'babelify';
import ngAnnotate from 'browserify-ngannotate';
import templateCache from 'gulp-angular-templatecache';
import rename from 'gulp-rename';
import notify from 'gulp-notify';
import ejs from 'gulp-ejs';
import inject from 'gulp-inject';
import concat from 'gulp-concat';
import sass from 'gulp-sass';
import cleanCSS from 'gulp-clean-css';
import uglify from 'gulp-uglify';
// Where our files are located
const jsFiles = "client/app/**/*.js";
const viewFiles = "client/app/**/*.html";
let interceptErrors = (error) => {
let args = Array.prototype.slice.call(arguments);
// Send error to notification center with gulp-notify
notify.onError({
title: 'Compile Error',
message: '<%= error.message %>'
}).apply(this, args);
// Keep gulp from hanging on this task
this.emit('end');
};
gulp.task('default', ['build'], () => {
console.log("Completed build.");
});
gulp.task('build', ['browserify', 'css'], () => {
gulp.start('html');
//gulp.start() will have to be replaced by gulp.series() when gulp 4.0 is released.
});
gulp.task('browserify', ['views'], () => {
return browserify(['./client/app/app.js'])
.transform(babelify, {presets: ["es2015"]})
.transform(ngAnnotate)
.bundle()
.on('error', interceptErrors)
.pipe(source('main.js'))
.pipe(buffer())
.pipe(uglify())
.pipe(gulp.dest('./build/'));
});
gulp.task('sass', function () {
return gulp.src('./client/app/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./client/app/'));
});
gulp.task('css', ['sass'], () => {
gulp.src('./client/app/*.css')
.pipe(cleanCSS())
.pipe(concat('style.css'))
.on('error', interceptErrors)
.pipe(gulp.dest('./build'));
});
gulp.task('html', () => {
const sources = gulp.src(['./build/*.js', './build/*.css'], {read: false});
return gulp.src("./client/index.html")
.pipe(inject(sources, {relative: true, ignorePath: '../build/'}))
.on('error', interceptErrors)
.pipe(gulp.dest('./build/'));
});
gulp.task('views', () => {
return gulp.src(viewFiles)
.pipe(templateCache({
standalone: true
}))
.on('error', interceptErrors)
.pipe(rename("app.templates.js"))
.pipe(gulp.dest('./client/app/config/'));
});
gulp.task('clean', () => {
del(['./build/**', '!./build']).then(paths => {
console.log('Deleted files and folders:\n', paths.join('\n'));
});
});