This repository has been archived by the owner on Feb 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
107 lines (93 loc) · 2.87 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
var gulp = require('gulp')
, concat = require('gulp-concat')
, sourcemaps = require('gulp-sourcemaps')
, uglify = require('gulp-uglify')
, ignore = require("gulp-ignore")
, runSequence = require('run-sequence')
, htmlreplace = require("gulp-html-replace")
, ngAnnotate = require('gulp-ng-annotate')
, cleanCSS = require('gulp-clean-css')
, htmlmin = require('gulp-htmlmin')
, sass = require('gulp-sass')
, del = require("del")
, inject = require("gulp-inject")
, jshint = require('gulp-jshint')
, server = require('gulp-server-livereload');
var vendorJs = [
"node_modules/angular/angular.min.js",
"node_modules/angular-animate/angular-animate.min.js",
"node_modules/angular-aria/angular-aria.min.js",
"node_modules/angular-messages/angular-messages.min.js",
"node_modules/angular-material//angular-material.min.js",
"node_modules/angular-ui-router/release/angular-ui-router.min.js"
];
gulp.task('js', function () {
return gulp.src(['app/*.js', 'app/**/*.js'])
.pipe(sourcemaps.init())
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(concat('app.js'))
.pipe(ngAnnotate())
.pipe(uglify())
.pipe(sourcemaps.write())
.pipe(gulp.dest('./dist'))
})
gulp.task("sass", function() {
return gulp.src(['assets/**/*.scss', "node_modules/angular-material/angular-material.scss"])
.pipe(sass({outputStyle: 'compact'}).on('error', sass.logError))
.pipe(concat('main.css'))
.pipe(cleanCSS())
.pipe(gulp.dest('./dist'));
})
gulp.task("html", function() {
return gulp.src('app/**/*.html')
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest('./dist/app'))
})
gulp.task("inject", function() {
var target = gulp.src("./index.html")
var sources = gulp.src([
"dist/vendor.js",
"dist/app.js",
"dist/main.css"
], {read: false})
return target.pipe(inject(sources, {
ignorePath: 'dist',
addRootSlash: false
}))
.pipe(htmlreplace({'dist': ''}))
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest("./dist"))
})
gulp.task('clean', function(cb) {
return del(['dist'], cb)
})
gulp.task("vendor",function() {
return gulp.src(vendorJs)
.pipe(concat('vendor.js'))
.pipe(gulp.dest('./dist'));
})
gulp.task('watch', ['js','sass','html'], function () {
gulp.watch(['app/**/*.js'], ['js'])
gulp.watch(['app/**/*.html'], ['html'])
gulp.watch(['assets/**/*.scss'], ['sass'])
})
gulp.task('build', function(cb) {
runSequence(
'clean',
['js','sass','html','vendor'],
'inject',
cb
)
})
gulp.task('webserver', function() {
gulp.src('dist')
.pipe(server({
livereload: true,
directoryListing: false,
open: true
}))
})
gulp.task("serve", ['build'], function() {
runSequence(['watch', 'webserver']);
})