-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGulpfile.js
148 lines (135 loc) · 4.23 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
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
// GULP DEPENDENCIES
var gulp = require('gulp'),
plugins = require('gulp-load-plugins')(),
runSequence = require('run-sequence'),
browserSync = require('browser-sync').create();
// PROJECT PATHS AND DEPENDENCIES
var setup = require('./setup.json'),
vhost = setup.vhost,
src = setup.src,
dest = setup.dest,
watch = setup.watch,
includes = setup.includes
cdnBackups = setup.src.cdnBackups;
// MOVE CDN BACKUPS INTO THEIR RESPECTIVE FOLDERS, NON-CDN'S SHOULD BE ADDED TO THE SCRIPTS AND STYLES INCLUDES ARRAYS WITHIN SETUP.JSON
gulp.task('cdn-backups', function() {
// JQUERY DEPENDENCY
gulp.src( cdnBackups + 'jquery/dist/jquery.min.js' )
.pipe(plugins.uglify())
.pipe(gulp.dest( dest.js ));
});
// STYLE DEVELOPMENT TASK
gulp.task('style', function() {
return gulp.src( src.styles )
.pipe(plugins.plumber(function(error) {
plugins.util.log(
plugins.util.colors.red(error.message),
plugins.util.colors.yellow('\r\nOn line: '+error.line),
plugins.util.colors.yellow('\r\nCode Extract: '+error.extract)
);
this.emit('end');
}))
.pipe(plugins.sass({
includePaths: includes.styles
}))
.pipe(plugins.rucksack({
autoprefixer: true
}))
.pipe(plugins.cssnano())
.pipe(plugins.rename('app.min.css'))
.pipe(gulp.dest( dest.css ))
.pipe(browserSync.stream());
});
// JAVASCRIPT DEVELOPMENT TASKS
// Run custom JS through babel transpiler
gulp.task('babel', function() {
return gulp.src( src.scripts )
.pipe(plugins.plumber(function(error) {
plugins.util.log(
plugins.util.colors.red(error.message),
plugins.util.colors.yellow('\r\nOn line: '+error.line),
plugins.util.colors.yellow('\r\nCode Extract: '+error.extract)
);
this.emit('end');
}))
.pipe(plugins.babel())
.pipe(plugins.concat('babel.js'))
.pipe(gulp.dest( dest.babel ));
});
// Concat custom JS file with the incdlues.scripts
gulp.task('scripts-concat', ['babel'], function() {
return includes.scripts.push(src.babel);
});
gulp.task('script', ['scripts-concat'], function() {
return gulp.src( includes.scripts )
.pipe(plugins.concat('app.js'))
.pipe(gulp.dest( dest.js ))
// .pipe(plugins.uglify()) // WHEN GOING LIVE... uncomment out this and the next two lines, comment out the two before, update the src tag of your websites js to the minified version
// .pipe(plugins.rename('app.min.js'))
// .pipe(gulp.dest( dest.js ))
.pipe(browserSync.stream());
});
// create production-ready JS file
gulp.task('script-production', function() {
return gulp.src( dest.js + "")
});
// IMAGE TASK - COPY & COMPRESS
gulp.task('image', function() {
return gulp.src( src.images )
.pipe(plugins.imagemin({
progressive: true,
interlaced: true,
svgoPlugins: [{removeUnknownsAndDefaults: false}, {cleanupIDs: false}]
}))
.pipe(gulp.dest( dir.assets + images ));
});
// ICONFONTS TASK - reference for svg setup: https://github.com/nfroidure/gulp-iconfont
gulp.task('iconfont', function() {
return gulp.src( src.svgs )
.pipe(plugins.iconfont({ fontName: 'website-icons' }))
.on('glyphs', function(glyphs, options) {
gulp.src( src.iconTemplate )
.pipe(plugins.consolidate('lodash', {
glyphs: glyphs,
fontName: 'website-icons',
fontPath: '../fonts/',
timestamp: Date.now(),
className: 'icon'
}))
.pipe(plugins.rename('iconfont.scss'))
.pipe(gulp.dest( dest.sass ));
})
.pipe(gulp.dest( dest.generatedFonts ));
});
// FONTS TASK
gulp.task('font', ["iconfont"], function() {
return gulp.src( src.fonts )
.pipe(gulp.dest( dest.fonts ))
});
// BROWSERSYNC WATCH TASK
gulp.task('watch', ['script', 'style'], function() {
// Serve files from this project's virtual host that has been configured with the server rendering this site
browserSync.init({
proxy : vhost,
files: [
{
options: {
ignored: '.*'
}
}
],
logPrefix: vhost,
browser: ["google chrome", "firefoxdeveloperedition", "firefox", "safari"],
reloadOnRestart: true,
notify: false
});
gulp.watch( watch.scripts, ["script"] );
gulp.watch( watch.styles, ["style"] );
gulp.watch( watch.views ).on("change", browserSync.reload);
});
// INITIALIZE PROJECT TASK
gulp.task('default', function(callback) {
runSequence('font',
['cdn-backups', 'style', 'script', 'image'],
callback);
});