-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathgulpfile.js
134 lines (119 loc) · 3.66 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
// See the readme file for instructions on installing and running gulp
/**
* Load Plugins.
*/
var gulp = require('gulp');
// Lazy-load in the order of plugins defined in package.json
// NOTE: prepend task/plugin names with fs object to access
var fs = require('gulp-load-plugins')({
rename: {
'gulp-combine-mq': 'combineMediaQueries',
'gulp-strip-debug': 'stripDebug'
}
});
/**
* Set Up Variables for css and javascript tasks
*/
// Grab all sass files in all subdirectories
var styleSrc = 'assets/src/scss/**/*.scss';
// Final output destination for compile sass file
var styleOutputDest = 'assets/css';
// Final output name to be served to the browser
var jsOutputName = 'main.js';
// Final output destination for jsOutputName
var jsOutputDest = 'assets/js';
// Scripts that are enqueued on specific pages
var singleScripts = [
'assets/src/js/customizer.js',
'assets/src/js/navigation.js',
'assets/src/js/skip-link-focus-fix.js'
];
// these scripts will end up compiled together into a 'main.js' file
var prodScripts = [
'assets/src/js/default.js',
];
/**
* Task: styles
*
* Compiles Sass, Autoprefixes it and Minifies CSS.
*
* This task does the following:
* 1. Gets the source scss file
* 2. Compiles Sass to CSS
* 3. Autoprefixes it and generates style.css and admin.css
* 4. Output the final css file
*/
gulp.task('styles', function () {
gulp.src(styleSrc)
.pipe(fs.plumber({
errorHandler: fs.notify.onError('Gulp!: <%= error.message %>')
}))
.pipe(fs.sass({
errLogToConsole: true
}))
.pipe(fs.autoprefixer(
'last 2 version',
'> 1%',
'safari 5',
'ie 9',
'opera 12.1',
'ios 6',
'android 4'))
.pipe(fs.combineMediaQueries())
.pipe(fs.cssmin())
.pipe(fs.rename({suffix: '.min'}))
.pipe(fs.size({ showFiles:true, showTotal: false }))
.pipe(gulp.dest(styleOutputDest))
});
/**
* Task: scripts
*
* Concatenate, uglify and output expanded and minified network javascript files.
*
* This task does the following:
* 1. Gets the source folder for vendor, custom js files. Array order is important here.
* 2. Concatenates all the script files into jsOutputName.js and output to the designated folder
* 3. Create jsOutputName.min.js and Uglifes/Minifies the script file
* 4. Place the final generated script file to the designated folder
*/
// Concatenate JS Files
gulp.task('prodscripts', function () {
return gulp.src(prodScripts)
.pipe(fs.plumber({
errorHandler: fs.notify.onError('Gulp!: <%= error.message %>')
}))
.pipe(fs.concat(jsOutputName))
.pipe(fs.rename({suffix: '.min'}))
.pipe(fs.stripDebug())
.pipe(fs.streamify(fs.uglify()))
.pipe(fs.size({ showFiles:true, showTotal: false }))
.pipe(gulp.dest(jsOutputDest));
});
/**
* 1) Unminified files written to output folder
* 2) Pipe maintained, .min added
* 3) Console Logs stripped
* 4) Files Minified
* 5) File Size Report generated for terminal
* 6) Pipe-out minified files
*/
gulp.task('singlescripts', function () {
return gulp.src(singleScripts)
.pipe(fs.plumber({
errorHandler: fs.notify.onError('Gulp!: <%= error.message %>')
}))
.pipe(gulp.dest(jsOutputDest))
.pipe(fs.rename({suffix: '.min'}))
.pipe(fs.stripDebug())
.pipe(fs.streamify(fs.uglify()))
.pipe(fs.size({ showFiles:true, showTotal: false }))
.pipe(gulp.dest(jsOutputDest));
});
// Default Task
gulp.task( 'default', ['styles', 'prodscripts', 'singlescripts'] );
// Watch Task
gulp.task('watch', ['styles', 'prodscripts', 'singlescripts'], function () {
gulp.watch(styleSrc, ['styles']);
gulp.watch(prodScripts, ['prodscripts']);
gulp.watch(singleScripts, ['singlescripts']);
});