This repository was archived by the owner on Dec 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgulpfile.js
More file actions
169 lines (143 loc) · 4.23 KB
/
gulpfile.js
File metadata and controls
169 lines (143 loc) · 4.23 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
//imports
var gulp = require('gulp');
var pump = require('pump');
var concatJS = require('gulp-concat');
var concatCSS = require('gulp-concat-css');
// var minifyCSS = require('gulp-clean-css');
// var minifyJS = require('gulp-uglify');
//file locations
var paths = {
dev: './src/', //files for development
dist: './dist/', //files for production
vendor: './node_modules/' //3rd party files
};
var source = {
css: [
//vendor
paths.vendor + 'bootstrap/dist/css/bootstrap.min.css',
//app wide
paths.dev + 'views/app/app.css',
//view/component specific
paths.dev + '**/styles.css'
],
js: {
app: [
//new app init
paths.dev + 'views/app/app.js',
//components
paths.dev + '**/component.js',
//directives
paths.dev + '**/directive.js',
//filters
paths.dev + '**/filter.js',
//services
paths.dev + 'services/*.js'
],
vendor: [
paths.vendor + 'angular/angular.min.js',
paths.vendor + 'angular-ui-router/release/angular-ui-router.min.js',
paths.dev + 'js/jquery.js',
paths.dev + 'js/trello.custom.js',
paths.vendor + 'howler/dist/howler.min.js',
paths.vendor + 'moment/min/moment.min.js',
paths.vendor + 'angular-inview/angular-inview.js'
]
},
forDist: [
//core files
paths.dev + 'manifest.json',
paths.dev + 'popup.html',
paths.dev + 'background.html',
//html templates
paths.dev + '**/template.html',
//background js
paths.dev + 'js/background.js',
//images
paths.dev + 'img/*.+(svg|png|jpg|gif)',
//sounds
paths.dev + 'snd/*.+(mp3)'
]
};
//public tasks
gulp.task('bundle_dev',['copy_to_dist','concat_app_js','concat_vendor_js','concat_css']);
// gulp.task('bundle_prod',['copy_to_dist','minify_app_js','minify_vendor_js','minify_css']);
gulp.task('watch_dev', watch_dev);
//private tasks
gulp.task('concat_app_js', concat_app_js);
gulp.task('concat_vendor_js', concat_vendor_js);
gulp.task('concat_css', concat_css);
// gulp.task('minify_app_js', ['concat_app_js'], minify_app_js);
// gulp.task('minify_vendor_js', ['concat_vendor_js'], minify_vendor_js);
// gulp.task('minify_css', ['concat_css'], minify_css);
gulp.task('copy_to_dist', copy_to_dist);
//////////////////////// FUNCTIONS ////////////////////////
//tasks to run after initial setup for development
function watch_dev() {
//re-build the bundles on file changes
detectChanges();
}
//watch for file changes and re-bundle
function detectChanges(){
gulp.watch(source.js.app, ['concat_app_js']).on('change', onChange);
gulp.watch(source.js.vendor, ['concat_vendor_js']).on('change', onChange);
gulp.watch(source.css, ['concat_css']).on('change', onChange);
gulp.watch(source.forDist, ['copy_to_dist']).on('change', onChange);
//log file that changed
function onChange(change) {
//split up the path to get the file name
var splitUpPath = change.path.split('/');
//log the file detected
console.log('"' + splitUpPath[splitUpPath.length - 1] + '" was ' + change.type);
}
}
//merge app js files together
function concat_app_js(cb){
pump([
gulp.src(source.js.app),
concatJS('app.js'),
gulp.dest(paths.dist + 'bundles/')
], cb);
}
//merge vendor js files together
function concat_vendor_js(cb){
pump([
gulp.src(source.js.vendor),
concatJS('vendor.js'),
gulp.dest(paths.dist + 'bundles/')
], cb);
}
//minify the app js bundle
function minify_app_js(cb){
pump([
gulp.src(paths.dist + 'bundles/app.js'),
minifyJS(),
gulp.dest(paths.dist + 'bundles/')
], cb);
}
//minify the vendor js bundle
function minify_vendor_js(cb){
pump([
gulp.src(paths.dist + 'bundles/vendor.js'),
minifyJS(),
gulp.dest(paths.dist + 'bundles/')
], cb);
}
//merge css files together
function concat_css(){
return gulp.src(source.css)
.pipe(concatCSS('app.css'))
.pipe(gulp.dest(paths.dist + 'bundles/'));
}
//minify the css bundle
function minify_css() {
return gulp.src(paths.dist + 'bundles/app.css')
.pipe(minifyCSS({
keepSpecialComments: 0
}))
.pipe(gulp.dest(paths.dist + 'bundles/'));
}
//copies source files needed for the dist folder
function copy_to_dist() {
return gulp.src(source.forDist, { base: paths.dev })
.pipe(gulp.dest(paths.dist));
}