forked from zetagraph/monoset
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
137 lines (127 loc) · 3.09 KB
/
gulpfile.js
File metadata and controls
137 lines (127 loc) · 3.09 KB
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
/*global -$ */
'use strict';
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var browserSync = require('browser-sync');
var reload = browserSync.reload;
// Error notifications
var reportError = function(error) {
$.notify({
title: 'Gulp Task Error',
message: 'Check the console.'
}).write(error);
console.log(error.toString());
this.emit('end');
}
// Sass processing
gulp.task('sass', function() {
return gulp.src('scss/**/*.scss')
.pipe($.sourcemaps.init())
// Convert sass into css
.pipe($.sass({
outputStyle: 'nested', // libsass doesn't support expanded yet
precision: 10
}))
// Show errors
.on('error', reportError)
// Autoprefix properties
.pipe($.autoprefixer({
browsers: ['last 2 versions']
}))
// Write sourcemaps
.pipe($.sourcemaps.write())
// Save css
.pipe(gulp.dest('styles'))
.pipe(browserSync.reload({
stream: true
}));
});
// process JS files and return the stream.
gulp.task('js', function () {
return gulp.src('scripts/**/*.js')
.pipe(gulp.dest('scripts'));
});
// Optimize Images
gulp.task('images', function() {
return gulp.src('images/**/*')
.pipe($.imagemin({
progressive: true,
interlaced: true,
svgoPlugins: [{
cleanupIDs: false
}]
}))
.pipe(gulp.dest('images'));
});
// JS hint
gulp.task('jshint', function() {
return gulp.src('scripts/*.js')
.pipe(reload({
stream: true,
once: true
}))
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'))
.pipe($.notify({
title: "JS Hint",
message: "JS Hint says all is good.",
onLast: true
}));
});
// Beautify JS
gulp.task('beautify', function() {
gulp.src('scripts/*.js')
.pipe($.beautify({indentSize: 2}))
.pipe(gulp.dest('scripts'))
.pipe($.notify({
title: "JS Beautified",
message: "JS files in the theme have been beautified.",
onLast: true
}));
});
// Compress JS
gulp.task('compress', function() {
return gulp.src('scripts/*.js')
.pipe($.sourcemaps.init())
.pipe($.uglify())
.pipe($.sourcemaps.write())
.pipe(gulp.dest('scripts'))
.pipe($.notify({
title: "JS Minified",
message: "JS files in the theme have been minified.",
onLast: true
}));
});
// Run drush to clear the theme registry
gulp.task('drush', function() {
return gulp.src('', {
read: false
})
.pipe($.shell([
'drush cc css-js',
]))
.pipe($.notify({
title: "Caches cleared",
message: "Drupal CSS/JS caches cleared.",
onLast: true
}));
});
// BrowserSync
gulp.task('browser-sync', function() {
//watch files
var files = [
'styles/main.css',
'scripts/**/*.js',
'images/**/*',
'templates/**/*.twig'
];
//initialize browsersync
browserSync.init(files, {
proxy: "d8.dev" // BrowserSync proxy, change to match your local environment
});
});
// Default task to be run with `gulp`
gulp.task('default', ['sass', 'browser-sync'], function() {
gulp.watch("scss/**/*.scss", ['sass']);
gulp.watch("scripts/**/*.js", ['js']);
});