forked from timroes/angular-es6-sample
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
94 lines (81 loc) · 2.22 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
var gulp = require('gulp');
var babelify = require('babelify');
var browserify = require('browserify');
var vinylSourceStream = require('vinyl-source-stream');
var vinylBuffer = require('vinyl-buffer');
// Load all gulp plugins into the plugins object.
var plugins = require('gulp-load-plugins')();
var src = {
html: 'src/**/*.html',
libs: 'src/libs/**',
scripts: {
all: 'src/scripts/**/*.js',
app: 'src/scripts/app.js'
}
};
var build = 'build/';
var out = {
libs: build + 'libs/',
scripts: {
file: 'app.min.js',
folder: build + 'scripts/'
}
}
gulp.task('html', function() {
return gulp.src(src.html)
.pipe(gulp.dest(build))
.pipe(plugins.connect.reload());
});
/* The jshint task runs jshint with ES6 support. */
gulp.task('jshint', function() {
return gulp.src(src.scripts.all)
.pipe(plugins.jshint({
esnext: true // Enable ES6 support
}))
.pipe(plugins.jshint.reporter('jshint-stylish'));
});
gulp.task('libs', function() {
/* In a real project you of course would use npm or bower to manage libraries. */
return gulp.src(src.libs)
.pipe(gulp.dest(out.libs))
.pipe(plugins.connect.reload());
});
/* Compile all script files into one output minified JS file. */
gulp.task('scripts', ['jshint'], function() {
var sources = browserify({
entries: src.scripts.app,
debug: true // Build source maps
})
.transform(babelify.configure({
// You can configure babel here!
// https://babeljs.io/docs/usage/options/
}));
return sources.bundle()
.pipe(vinylSourceStream(out.scripts.file))
.pipe(vinylBuffer())
.pipe(plugins.sourcemaps.init({
loadMaps: true // Load the sourcemaps browserify already generated
}))
.pipe(plugins.ngAnnotate())
.pipe(plugins.uglify())
.pipe(plugins.sourcemaps.write('./', {
includeContent: true
}))
.pipe(gulp.dest(out.scripts.folder))
.pipe(plugins.connect.reload());
});
gulp.task('serve', ['build', 'watch'], function() {
plugins.connect.server({
root: build,
port: 4242,
livereload: true,
fallback: build + 'index.html'
});
});
gulp.task('watch', function() {
gulp.watch(src.libs, ['libs']);
gulp.watch(src.html, ['html']);
gulp.watch(src.scripts.all, ['scripts']);
})
gulp.task('build', ['scripts', 'html', 'libs']);
gulp.task('default', ['serve']);