-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
86 lines (68 loc) · 2.21 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
/**
* Gulpfile for using browser-sync reload server with Drupal 8 development.
*
* @author Kent Richards
*/
var gulp = require('gulp');
// ========== CONFIG ==========
var webRoot = './web';
var siteDir = webRoot + '/sites/default';
var themeDir = webRoot + '/themes/mytheme';
var sassSrcDir = themeDir + '/assets/sass';
var sassDestDir = themeDir + '/css';
// Patterns that Sass should watch for reprocessing.
// Glob pattern documentation: https://github.com/isaacs/node-glob.
var sassWatchPatterns = [
sassSrcDir + '/**.scss'
];
// Host:port that the backend server (Apache, Nginx..) is listening on.
var reloadBackend = 'localhost:8081';
// Port used for main web connection.
var reloadFrontendPort = 8080;
// Patterns that reload server should watch for changes.
// Note: Any stylesheet compiled by Sass shouldn't need to be watched here
// because they should be injected into the HTML automatically by the
// 'sass' task.
var reloadWatchPatterns = [
themeDir + '/**/*.@(png|jpe?g|gif|ico|svg|tiff)'
];
// Patterns for files that require a <code>drush cr</code> when changed.
var crWatchPatterns = [
siteDir + '/**/*.yml',
themeDir + '/**/*.yml',
themeDir + '/**/*.theme',
themeDir + '/templates/**/*.*'
];
// ========== SASS ==========
var sass = require('gulp-sass');
gulp.task('sass', function () {
return gulp.src(sassSrcDir + '/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest(sassDestDir))
.pipe(browserSync.stream());
});
gulp.task('sass:watch', ['sass'], function () {
gulp.watch(sassWatchPatterns, ['sass']);
});
// ========== BROWSER-SYNC / RELOAD ==========
var browserSync = require('browser-sync');
var reload = browserSync.reload;
gulp.task('browser-sync', function() {
browserSync({
proxy: reloadBackend,
port: reloadFrontendPort,
open: true,
notify: false
});
});
// ========== DRUSH CACHE RESET ==========
var run = require('gulp-run');
gulp.task('cr', function() {
var cmd = 'drush cr';
return run(cmd, { cwd: webRoot }).exec();
});
// ========== MAIN WATCH ==========
gulp.task('watch', ['browser-sync', 'sass:watch'], function () {
gulp.watch(reloadWatchPatterns, reload);
gulp.watch(crWatchPatterns, ['cr', reload]);
});