-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGulpfile.js
113 lines (89 loc) · 3.05 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
108
109
110
111
112
113
var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();
var mainBowerFiles = require('main-bower-files');
var paths = {
scripts: 'app/**/*.js',
styles: ['app/**/*.{css,scss}'],
index: 'app/index.html',
partials: ['app/**/*.html', '!app/index.html'],
dest: './dest'
};
var pipes = {};
pipes.cleanDest = function () {
return gulp.src('dest/', {read: false})
.pipe(plugins.clean());
};
pipes.builtPartialScripts = function() {
return gulp.src(paths.partials)
.pipe(gulp.dest(paths.dest));
};
pipes.builtAppStyles = function() {
return gulp.src(paths.styles)
.pipe(plugins.concat('app.css'))
.pipe(gulp.dest(paths.dest));
};
pipes.builtVendorStyles = function() {
return gulp.src(mainBowerFiles('**/*.css'))
.pipe(plugins.concat('vendor.css'))
.pipe(gulp.dest(paths.dest));
};
pipes.builtVendorScripts = function() {
return gulp.src(mainBowerFiles('**/*.js'))
.pipe(pipes.orderVendorScripts())
.pipe(plugins.concat('vendor.js'))
// .pipe(plugins.uglify())
.pipe(gulp.dest(paths.dest));
};
//built app acripts
pipes.builtAppScripts = function() {
return gulp.src(paths.scripts)
.pipe(pipes.orderAppScripts())
.pipe(plugins.concat('app.js'))
.pipe(plugins.uglify())
.pipe(gulp.dest(paths.dest));
};
//order vendor scripts
pipes.orderVendorScripts = function() {
return plugins.order(['jquery.js', 'angular.js']);
};
//put index.js into first order
pipes.orderAppScripts = function() {
return plugins.order(['app/index.js', paths.scripts]);
};
//copy bower-components into app folder
pipes.bowerFiles = function() {
return gulp.src(mainBowerFiles())
.pipe(gulp.dest(paths.dest + '/bower_components'));
};
pipes.builtIndex = function() {
var vendorStyles = pipes.builtVendorStyles();
var vendorScripts = pipes.builtVendorScripts();
var appScripts = pipes.builtAppScripts();
var appStyles = pipes.builtAppStyles();
pipes.builtPartialScripts();
return gulp.src('app/index.html')
.pipe(gulp.dest(paths.dest))
.pipe(plugins.inject(vendorScripts, {relative:true, name:'bowerjs'}))
.pipe(plugins.inject(vendorStyles, {relative:true, name:'bowercss'}))
// .pipe(plugins.inject(gulp.src(mainBowerFiles()), {relative:true, name:'bower'}))
.pipe(plugins.inject(appScripts, {relative:true}))
.pipe(plugins.inject(appStyles, {relative:true}))
.pipe(gulp.dest(paths.dest));
};
gulp.task('clean-app', pipes.cleanDest);
gulp.task('build-app', ['clean-app'], pipes.builtIndex);
gulp.task('build-app', ['clean-app'], pipes.builtIndex);
gulp.task('watch', ['build-app'], function() {
gulp.watch(paths.index, function() {
return pipes.builtIndex();
});
gulp.watch(paths.scripts, function() {
return pipes.builtAppScripts();
});
gulp.watch(paths.styles, function() {
return pipes.builtAppStyles();
});
gulp.watch(paths.partials, function() {
return pipes.builtPartialScripts();
});
});