forked from ixkaito/bathe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
175 lines (154 loc) · 3.76 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
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
'use strict';
/**
* Gulp modules
*/
var gulp = require('gulp');
var newer = require('gulp-newer');
var plumber = require('gulp-plumber');
var browserSync = require('browser-sync');
var sass = require('gulp-sass');
var autoprefixer = require('gulp-autoprefixer');
var compass = require('gulp-compass');
var imagemin = require('gulp-imagemin');
var pngquant = require('imagemin-pngquant');
var browserify = require('browserify');
var watchify = require('watchify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var uglify = require('gulp-uglify');
var watch = require('gulp-watch');
// Load configurations set variables
var config = require('./gulpconfig.json');
var tasks = [];
var paths = {};
var jsSrc = [];
if (config.tasks.compass) {
config.tasks.sass = false;
}
Object.keys(config.tasks).forEach(function (key) {
if (config.tasks[key]) {
tasks.push(key);
}
});
Object.keys(config.paths).forEach(function (key) {
if (key != 'assets') {
if (config.paths.assets === '') {
paths[key] = './' + config.paths[key];
} else {
paths[key] = config.paths.assets + '/' + config.paths[key];
}
}
});
for (var i = 0; i <= config.js.src.length - 1; i++) {
jsSrc.push(paths.jsSrc + '/' + config.js.src[i]);
}
/**
* Browser
*/
gulp.task('browser-sync', function () {
browserSync({
proxy: config.siteurl
});
});
gulp.task('browser-reload', function () {
browserSync.reload();
});
/**
* Sass
*/
gulp.task('sass', function () {
return gulp.src(paths.sass + '/**/*')
.pipe(sass().on('error', sass.logError))
.pipe(sass({outputStyle: config.sass.outputStyle}))
.pipe(autoprefixer({ browsers: config.autoprefixer.browsers }))
.pipe(gulp.dest(paths.css));
});
/**
* Compass
*/
gulp.task('compass', function () {
return gulp.src(paths.sass + '/**/*')
.pipe(plumber())
.pipe(compass({
config_file: config.compass.config,
style: config.compass.style,
comments: config.compass.comments,
css: paths.css,
sass: paths.sass,
image: paths.images
}));
});
/**
* Imagemin
*/
gulp.task('imagemin', function () {
return gulp.src(paths.imageSrc + '/**/*')
.pipe(plumber())
.pipe(newer(paths.images))
.pipe(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use: [pngquant()]
}))
.pipe(gulp.dest(paths.images));
});
/**
* Browserify and Watchify
*/
gulp.task('browserify', function () {
return compile(false);
});
gulp.task('watchify', function () {
return compile(true);
});
function compile(watching) {
var b = browserify(jsSrc);
if (watching) {
b = watchify(b);
}
function bundle() {
return b.bundle()
.pipe(source(config.js.dist))
.pipe(buffer())
.pipe(uglify())
.pipe(gulp.dest(paths.js));
}
b.on('update', function () {
bundle();
});
return bundle();
}
/**
* Watch files for changes, recompile, and reload the browser.
*/
gulp.task('watch', ['watchify'], function () {
if (config.tasks.imagemin) {
watch(paths.imageSrc + '/**/*', function () {
gulp.start('imagemin');
});
}
if (config.tasks.compass) {
watch(paths.sass + '/**/*', function () {
gulp.start('compass');
});
} else if (config.tasks.sass) {
watch(paths.sass + '/**/*', function () {
gulp.start('sass');
});
}
if (config.tasks['browser-sync']) {
watch([
'./**/*.php',
paths.css + '/**/*',
paths.js + '/**/*',
paths.images + '/**/*'
], function () {
gulp.start('browser-reload');
});
}
});
/**
* Default task, running just `gulp` will compile the sass,
* bundle the js, launch BrowserSync & watch files.
*/
gulp.task('default', tasks);