-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gulpfile.js
86 lines (71 loc) · 2.38 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
var themename = 'YOUR_THEME_NAME';
// YOUR_THEME_NAME is the name of the folder under 'themes' folder. i.e. twentynineteen
var gulp = require('gulp'),
// Prepare and optimize code etc
autoprefixer = require('autoprefixer'),
browserSync = require('browser-sync').create(),
image = require('gulp-image'),
jshint = require('gulp-jshint'),
// postcss = require('postcss'),
sass = require('gulp-sass'),
sourcemaps = require('gulp-sourcemaps'),
// Only work with new or updated files
newer = require('gulp-newer'),
// Name of working theme folder
root = '../' + themename + '/',
scss = root + 'sass/',
js = root + 'js/',
img = root + 'images/',
languages = root + 'languages/';
//
sass.compiler = require('node-sass');
// CSS via Sass and Autoprefixer
gulp.task('css', function() {
return gulp.src(scss + '{style.scss,rtl.scss}')
// .pipe(sourcemaps.init())
.pipe(sass({
outputStyle: 'expanded',
indentType: 'tab',
indentWidth: '1'
}).on('error', sass.logError))
// .pipe(postcss([
// autoprefixer('last 2 versions', '> 1%')
// ]))
// .pipe(sourcemaps.write(scss + 'maps'))
.pipe(gulp.dest(root));
});
// Optimize images through gulp-image
gulp.task('images', function() {
return gulp.src(img + 'RAW/**/*.{jpg,JPG,png}')
.pipe(newer(img))
.pipe(image())
.pipe(gulp.dest(img));
});
// JavaScript
gulp.task('javascript', function() {
return gulp.src([js + '*.js'])
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(gulp.dest(js));
});
// Watch everything
gulp.task('watch', function() {
browserSync.init({
open: 'external',
// Since I used 'Flywheel by Local' to host my local wordpress site, so i need to paste the url here.
proxy: 'http://YOUR_SITE.local',
port: 8080
});
// gulp.watch([root + '**/*.css', root + '**/*.scss' ], ['css']);
// gulp.watch(js + '**/*.js', ['javascript']);
// gulp.watch(img + 'RAW/**/*.{jpg,JPG,png}', ['images']);
// gulp.watch(root + '**/*').on('change', browserSync.reload);
// gulp.watch([root + '**/*.css', root + '**/*.scss' ], gulp.series('css'));
gulp.watch([ root + '**/*.scss' ], gulp.series('css'));
gulp.watch(js + '**/*.js', gulp.series('javascript'));
gulp.watch(img + 'RAW/**/*.{jpg,JPG,png}', gulp.series('images'));
gulp.watch(root + '**/*').on('change', browserSync.reload);
});
// Default task (runs at initiation: gulp --verbose)
//gulp.task('default', ['watch']);
gulp.task('default', gulp.series('watch'));