-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
142 lines (125 loc) · 3.74 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
// Require all dev dependencies.
var gulp = require('gulp'),
minify = require('gulp-minify'),
watch = require('gulp-watch'),
cleanCSS = require('gulp-clean-css'),
rename = require('gulp-rename'),
postcss = require('gulp-postcss'),
bless = require('gulp-bless'),
sass = require('gulp-sass'),
zip = require('gulp-zip'),
autoprefixer = require('autoprefixer'),
browserSync = require('browser-sync').create(),
imagemin = require('gulp-imagemin');
// me.js contains vars to your specific setup
var me = require('../me.js');
var WEBSITE = me.WEBSITE,
BASE_NAME = __dirname.match(/([^\/]*)\/*$/)[1];
// JS source, destination, and excludes.
var JS_EXCLD = '!assets/js/*.min.js',
JS_SRC = 'assets/js/*.js',
JS_DEST = 'assets/js/';
// CSS and SASS src, dest, and exclude.
var CSS_EXCLD = '!assets/css/*.min.css',
CSS_SRC = 'assets/css/*.css',
CSS_DEST = 'assets/css/',
SASS_SRC = 'assets/scss/*.scss';
// Zip src and options.
var ZIP_SRC_ARR = ['./**','!./composer.*', '!./gulpfile.js', '!./package.json', '!./README.md', '!./phpcs.xml', '!./phpunit.xml.dist', '!./{node_modules,node_modules/**}', '!./{bin,bin/**}', '!./{dist,dist/**}', '!./{vendor,vendor/**}', '!./{tests,tests/**}' ],
ZIP_OPTS = { base: '..' };
// PHP Source.
var PHP_SRC = '**/*.php';
/*******************************************************************************
* Gulp Tasks
******************************************************************************/
/**
* Default gulp task. Initializes browserSync proxy server and watches src files
* for any changes.
*
* CMD: gulp
*/
gulp.task('default', function() {
browserSync.init({
proxy: WEBSITE
});
gulp.watch( SASS_SRC, ['build-sass']);
gulp.watch( CSS_SRC, ['build-css']);
gulp.watch( JS_SRC , ['js-watch']);
gulp.watch( PHP_SRC, function(){
browserSync.reload();
});
});
/**
* JS Watch task. This is a dependency task for the default gulp task that
* builds the js files and reloads the browser in the correct order
*
* CMD: None. Not meant to be run as standalone command.
*/
gulp.task('js-watch', ['build-js'], function(){
browserSync.reload();
});
/**
* Build CSS task. This task adds vendor specific prefixes to CSS rules, minifies
* the files and injects the changes to the browser.
*
* CMD: gulp build-css
*/
gulp.task('build-css', function() {
gulp.src( [ CSS_SRC, CSS_EXCLD ] )
.pipe(postcss([
autoprefixer({browsers: ['> 5% in US']})
]))
//.pipe(bless())
.pipe(cleanCSS({compatibility: 'ie8'}))
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest( CSS_DEST ))
.pipe(browserSync.stream());
});
/**
* Compiles SCSS into regular CSS.
*
* CMD: gulp build-sass
*/
gulp.task('build-sass', function() {
gulp.src( SASS_SRC )
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest(CSS_DEST));
});
/**
* Minifies JS files.
*
* CMD: gulp build-js
*/
gulp.task('build-js', function(){
gulp.src( [ JS_SRC, JS_EXCLD ] )
.pipe(minify({
ext:{
src:'.js',
min:'.min.js'
},
noSource: true
}))
.pipe(gulp.dest( JS_DEST ));
});
gulp.task('build-img', function(){
gulp.src('assets/images/*')
.pipe(imagemin())
.pipe(gulp.dest('assets/images'));
});
/**
* Executes all of the build tasks in the correct sequence.
*
* CMD: gulp build
*/
gulp.task('build', ['build-sass','build-css','build-js', 'build-img']);
/**
* Creates a zip file of the current project without any of the config and dev
* files and saves it under the 'dist' folder.
*
* CMD: gulp zip
*/
gulp.task('zip', function(){
return gulp.src( ZIP_SRC_ARR, ZIP_OPTS )
.pipe( zip( BASE_NAME + '.zip' ) )
.pipe( gulp.dest('dist') );
});