-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
222 lines (171 loc) · 4.98 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
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*
*
*
* This is an automation of CSS HTML starter Pack
*
* When you download it or find it as it is, you need to install by typing cmd:
* CMD: npm install
*
*After installing all dependencies you can run it by typing cmd:
*CMD: gulp
*
* Images will be minified, CSS will be minified and prefixes will be added,
* JS will be uglified andall JS files will be combined into ONE file and
* HTML files and all other minified & uglified files will be transferred into your
* distribution folder. when you build your project for distribution.
*
* When you are ready for distribution or want to build, you have to type cmd:
*CMD: gulp build
*
* If you want RTL support in your CSS, you have to type this cmd after building your project:
* CMD: gulp rtl-css
*
*
*/
//
// ALL Variables
//
var gulp = require('gulp'),
gutil = require('gulp-util'),
rename = require('gulp-rename'),
scss = require('gulp-ruby-sass'),
sourcemaps = require('gulp-sourcemaps'),
postcss = require('gulp-postcss'),
autoprefixer = require('autoprefixer'),
rtlcss = require('rtlcss'),
cleanCSS = require('gulp-clean-css'),
jshint = require('gulp-jshint'),
uglify = require('gulp-uglify'),
concat = require('gulp-concat'),
cache = require('gulp-cache'),
imagemin = require('gulp-imagemin'),
livereload = require('gulp-livereload'),
rootDir = './',
source = 'assets/',
destination = 'assets/distribution/';
// JS files are linting by an linter and combining into one file
gulp.task('js', function() {
gulp.src([
'!assets/js/scripts/jquery.js', // ignoring Jquery - call it in WP by using function or make <script> tag of it
source + 'js/scripts/*.js'
])
.pipe(jshint('./.jshintrc'))
.pipe(jshint.reporter('jshint-stylish'))
.pipe(concat('scripts.min.js'))
.pipe(gulp.dest(source + 'js/'))
.pipe(livereload());
cache.clearAll();
});
// SCSS is being converted into CSS
gulp.task('scss-to-css',function () {
return scss(source + 'scss/style.scss', {
sourcemap: false
// style: 'compressed'
})
.on('error', function (err) {
console.error('Error!', err.message);
})
.pipe(sourcemaps.write())
.pipe(gulp.dest(rootDir))
.pipe(livereload());
cache.clearAll();
});
/*
*
* Adding RTL support in separate CSS
* DO NOT RUN THIS CMD BEFORE BUILDING YOUR PROJECT! ("gulp build")
*
*/
gulp.task('rtl-css', function() {
console.log('[ RTL ] Converting CSS to RTL-CSS...');
gulp.src(destination + 'css/style.css')
.pipe(postcss([
rtlcss(),
]))
.on('error', function (err) {
console.error('Error!', err.message);
})
.pipe(rename({ extname: '-rtl.css' }))
.pipe(gulp.dest(rootDir));
console.log('[ RTL ] RTL-CSS task completed!');
console.log('[ RTL ] Saved to /rtl/style.css');
console.log(' ');
});
// When you are ready to distribute your project.. use this CMD: gulp build
gulp.task('build', function() {
/*
*
* Minifying images
*
*/
console.log(' ');
console.log('[ ============================================ ]');
console.log('[ ============================================ ]');
console.log(' ');
console.log('[ IMG ] Minifying images...');
gulp.src(source + 'img/*')
.pipe(cache(
imagemin({
interlaced: true,
progressive: true,
optimizationLevel: 8
})
))
.pipe(gulp.dest(destination + 'img'));
console.log('[ IMG ] Images minified successfully! ');
console.log(' ');
/*
*
* Minifying and combining all JS files
*
*/
console.log('[ JS ] Minifying and Combining all JS files...');
gulp.src([
source + 'js/scripts.min.js',
])
.pipe(uglify())
.pipe(gulp.dest(destination + 'js/'));
console.log('[ JS ] Minifying and combining completed!');
console.log(' ');
/*
*
* Minifying and adding prefixes in CSS
*
*/
console.log('[ CSS ] Adding prefixes...');
console.log('[ CSS ] Minifying CSS...');
gulp.src(source + 'css/style.css')
.pipe(postcss([
autoprefixer(),
]))
.on('error', function (err) {
console.error('Error!', err.message);
})
.pipe(cleanCSS())
.pipe(rename({ extname: '.min.css' }))
.pipe(gulp.dest(destination + 'css'));
console.log('[ CSS ] Prefixes & Minifying completed!');
/*
*
* Clearing all cache of minified images
*
*/
console.log('[ X ] Clearing all Cache(s) ');
cache.clearAll();
console.log(' ');
console.log('[ ============================================ ]');
console.log('[ ============================================ ]');
console.log(' ');
});
// Files that are being watched for Live-Reload
gulp.task('watch', function() {
livereload.listen(35729);
gulp.watch('**/*.php').on('change', function(file) {
livereload.changed(file.path);
});
gulp.watch(source + 'js/scripts/*', ['js']);
gulp.watch(source + 'scss/**/*', ['scss-to-css']);
gulp.watch(source + 'css/*');
});
// tasks to perform for first time when you type CMD (gulp)
gulp.task('default', ['scss-to-css', 'js', 'watch']);