-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
80 lines (68 loc) · 1.91 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
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var source = 'source/';
var config = {
source: source,
index: source + 'index.html',
optimize: {
app: 'app.js',
lib: 'lib.js'
},
build: 'build/'
};
gulp.task('wiredep', function(){
var wiredep = require('wiredep').stream;
return gulp.src(config.index)
.pipe(wiredep())
.pipe(gulp.dest(config.source));
});
gulp.task('inject', ['wiredep'], function(){
return gulp.src(config.index)
.pipe($.inject(gulp.src(config.source + 'app/**/*.js').pipe($.angularFilesort()), {relative: true}))
.pipe($.inject(gulp.src(config.source + '**/*.css'), {relative: true}))
.pipe(gulp.dest(config.source));
});
gulp.task('optimize', ['inject'], function(){
var assets = $.useref.assets();
var cssFilter = $.filter('**/*.css');
var jsAppFilter = $.filter('**/' + config.optimize.app);
var jsLibFilter = $.filter('**/' + config.optimize.lib);
gulp.src(config.index)
.pipe(assets)
// css
.pipe(cssFilter)
.pipe($.minifyCss())
.pipe(cssFilter.restore())
// app.js
.pipe(jsAppFilter)
.pipe($.ngAnnotate({add: true}))
.pipe($.uglify())
.pipe(jsAppFilter.restore())
// lib.js
.pipe(jsLibFilter)
.pipe($.uglify())
.pipe(jsLibFilter.restore())
// rev
// .pipe($.rev())
.pipe(assets.restore())
.pipe($.useref())
// .pipe($.revReplace())
.pipe(gulp.dest(config.build));
});
gulp.task('build', ['optimize', 'mv']);
gulp.task('default', ['inject']);
gulp.task('mv', function(){
gulp.src([
config.source + 'background.js',
config.source + 'manifest.json',
])
.pipe(gulp.dest(config.build));
gulp.src(config.source + 'app/**/*.html')
.pipe(gulp.dest(config.build + '/app'));
gulp.src(config.source + 'img/**/*')
.pipe(gulp.dest(config.build + '/img'));
});
gulp.task('clean', function(){
return gulp.src(config.build)
.pipe($.clean());
});