forked from lucijanblagonic/wordcamp-style-guide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
96 lines (86 loc) · 3.78 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
// Requiring Gulp
var gulp = require('gulp'),
sass = require('gulp-sass'), // Requiring gulp-sass (compiles SCSS)
sourcemaps = require('gulp-sourcemaps'), // Requiring sourcemaps (helps working locally)
autoprefixer = require('gulp-autoprefixer'), // Requiring autoprefixer (adds browser prefixes)
cssnano = require('gulp-cssnano'), // Requiring cssnano (minifies CSS)
imagemin = require('gulp-imagemin'), // Requiring imagemin (lossless image optimization)
plumber = require('gulp-plumber'), // Requiring plumber ()
notify = require("gulp-notify"), // Requiring notify ()
browserSync = require('browser-sync'), // Requiring browser-sync (browser refresh)
shell = require('gulp-shell'), // Requiring gulp-shell (used for KSS node)
kssNode = 'node ' + __dirname + '/node_modules/kss/bin/kss-node '; // Require kss-node
// Start KSS (style guide) task
gulp.task('kss', shell.task(
[kssNode + '--config source/kss-config.json']));
// [kssNode + '--xdemo']));
// Start browserSync server
gulp.task('browserSync', function() {
browserSync({
// Display the build folder first
startPath: 'styleguide',
server: {
// Start in root (important for relative paths between build and style guide folders)
baseDir: './'
}
})
})
// Start browserSync server proxying live site
gulp.task('browserSyncLive', function() {
browserSync({
proxy: 'https://2019.vienna.wordcamp.org/',
serveStatic: ['build/assets/stylesheets', 'build/assets/images'],
rewriteRules: [
{
match: /\?custom-css=b51a0b2c7b/g,
fn: function() {
return '/style.css';
}
},
{
match: /wp-admin\/admin-ajax.php\?action=wordcamp_remote_css&ver=\d{4,}/g,
fn: function() {
return '/style.css';
}
}
]
})
})
// Start stylesheets task
gulp.task('stylesheets', function() {
gulp.src('source/assets/stylesheets/*.scss') // Get all *.scss files
.pipe(plumber({errorHandler: notify.onError("Error: <%= error.message %>")})) // Show error
.pipe(sourcemaps.init()) // Initialize sourcemap plugin
.pipe(sass().on('error', sass.logError)) // Compiling sass
.pipe(autoprefixer('last 2 version')) // Adding browser prefixes
.pipe(sourcemaps.write()) // Writing sourcemaps
.pipe(cssnano()) // Compress
.pipe(gulp.dest('build/assets/stylesheets'))
.pipe(browserSync.reload({
stream: true
}));
})
// Start images task
gulp.task('images', function() {
gulp.src('source/assets/images/**')
.pipe(imagemin())
.pipe(gulp.dest('build/assets/images'));
});
// Start watch groups of tasks
gulp.task('default', ['browserSync', 'stylesheets', 'images', 'kss'], function() {
gulp.watch('source/assets/stylesheets/**/*.scss', ['stylesheets']); // Watch for SCSS changes
gulp.watch('source/assets/images/**/*', ['images']); // Watch for image changes
gulp.watch('source/**', ['kss']); // Watch for style guide changes
gulp.watch('build/**.html', browserSync.reload);
gulp.watch('styleguide/**.html', browserSync.reload);
});
// Start watch groups of tasks
gulp.task('watchLive', ['browserSyncLive', 'stylesheets', 'images', 'kss'], function() {
gulp.watch('source/assets/stylesheets/**/*.scss', ['stylesheets']); // Watch for SCSS changes
gulp.watch('source/assets/images/**/*', ['images']); // Watch for image changes
gulp.watch('source/**', ['kss']); // Watch for style guide changes
gulp.watch('build/**.html', browserSync.reload);
gulp.watch('styleguide/**.html', browserSync.reload);
});
// Start build task
gulp.task('build', ['stylesheets', 'images', 'kss'], function() {})