Repository navigation
Expand file tree
/
Copy pathgulpfile.js
More file actions
204 lines (173 loc) · 5.47 KB
/
Copy pathgulpfile.js
File metadata and controls
204 lines (173 loc) · 5.47 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
|==========================================================================
| Gulp Modules
|==========================================================================
|
|
|
*/
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var merge = require('merge-stream');
/*
|==========================================================================
| Setting Paths for Sourcing and Destination
|==========================================================================
*/
var $assets = {
styles: 'site/resources/scss/**/*.scss',
scripts: 'site/resources/js/**/*.js',
fonts: 'site/resources/fonts/**/*',
},
$bootstrap = 'node_modules/bootstrap-sass/';
/**
|==========================================================================
| Delete the "build" Folder
|==========================================================================
*/
gulp.task('clean', function () {
return gulp.src('build')
.pipe($.clean({force:true}));
});
/*
|==========================================================================
| Styles Tasks
|==========================================================================
*/
gulp.task('styles', function(){
// So size can be sent to gulp-notify
const s = $.size();
// .src is where the files come from that this file will use to build
return gulp.src([
$assets.styles
])
// error reporting
.pipe($.plumber({
errorHandler: function (error) {
console.log(error.message);
this.emit('end');
}
}))
// compilation of the SASS
.pipe($.sass({
// nested, expanded, compact, compressed
outputStyle: "compressed",
includePaths: [
// this line lets you put the full relative path to a scss file from project root. no more "../../../"!
"./",
$bootstrap + "assets/stylesheets/",
]
}))
// autoprefixing the compiled CSS (these settings as currently defined by bootstrap)
.pipe($.autoprefixer({
browsers: [
"Android 2.3",
"Android >= 4",
"Chrome >= 20",
"Firefox >= 24",
"Explorer >= 8",
"iOS >= 6",
"Opera >= 12",
"Safari >= 6"
],
cascade: false
}))
// get the size of the file created
.pipe(s)
// send the file to the directory
.pipe(gulp.dest('build/css/'))
// give user feedback
.pipe($.notify({
message: () => `Styles Merged! Size: ${s.prettySize}`,
onLast: true
}));
});
// Styles Minification for Production
gulp.task('styles:min', function(){
const s = $.size();
return gulp.src('build/css/*.css')
.pipe($.cleanCss())
.pipe(s)
.pipe(gulp.dest('build/css/'))
.pipe($.notify({
message: () => `Styles Scrubbed! Size: ${s.prettySize}`,
onLast: true
}));
})
/*
|==========================================================================
| Scripts Task
|==========================================================================
*/
gulp.task('scripts', function(){
var SCRIPTS = [
// I wish there was a better way to do this, but there isn't!
// Add all the scripts to bundle in here. Example:
//
// 'node_modules/bootstrap/js/bootstrap.js',
// site/js
$assets.scripts,
];
// So size can be sent to gulp-notify
const s = $.size();
// .src is where the files come from that this file will use to build
return gulp.src(SCRIPTS)
// uglify the scripts by mashing them together in a single line per script with single letters as variables
.pipe($.uglify({
// preserveComments: "license",
}))
// take all the uglified scripts and put them in one file
.pipe($.concat('app.js'))
// size of the file created
.pipe(s)
// save
.pipe(gulp.dest('build/js/'))
// give user feedback
.pipe($.notify({
message: () => `Scripts Merged! Size: ${s.prettySize}`,
onLast: true
}));
});
/*
|==========================================================================
| Fonts Task
|==========================================================================
*/
gulp.task('fonts', function() {
// .src is where the files come from that this file will use to build
return gulp.src([
$assets.fonts,
$bootstrap + 'fonts/**/*'
])
// save
.pipe(gulp.dest('build/fonts/'))
// give user feedback
.pipe($.notify({
message: 'Fonts Copied, Locked and Loaded!',
onLast: true
}));
});
/*
|==========================================================================
| Watch Task
|==========================================================================
|
| Runs continuously on "gulp watch"
|
*/
gulp.task('watch', function() {
gulp.watch($assets.styles, gulp.parallel('styles'));
gulp.watch($assets.scripts, gulp.parallel('scripts'));
});
/*
|==========================================================================
| Default Task: No Cleaning
|==========================================================================
*/
gulp.task('default', gulp.parallel('styles', 'scripts', 'fonts'));
/*
|==========================================================================
| Build Task: With Cleaning
|==========================================================================
*/
gulp.task('build', gulp.series('clean', 'styles', 'styles:min', 'scripts', 'fonts'));