-
Notifications
You must be signed in to change notification settings - Fork 5
/
gulpfile.js
145 lines (117 loc) · 3.27 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
// gulpfile.js - https://jsua.co/mm-gulp
'use strict'; // http://www.w3schools.com/js/js_strict.asp
// 1. LOAD PLUGINS
var gulp = require('gulp');
var bourbon = require('bourbon').includePaths;
var neat = require('bourbon-neat').includePaths;
var p = require('gulp-load-plugins')({ // This loads all the other plugins.
DEBUG: false,
pattern: ['gulp-*', 'gulp.*', 'del', 'run-*', 'browser*', 'vinyl-*'],
rename: {
'vinyl-source-stream': 'source',
'vinyl-buffer': 'buffer'
},
});
// 2. CONFIGURATION
var
src = 'source/', // The Middleman source folder
dest = '.tmp/', // The "hot" build folder used by Middleman's external pipeline
development = p.environments.development,
production = p.environments.production,
css = {
in: src + 'assets/stylesheets/**/*.{css,scss,sass}',
out: dest + 'assets/stylesheets/',
},
sassOpts = {
imagePath: '../assets/images',
includePaths: [bourbon, neat],
errLogToConsole: true
},
autoprefixerOpts = {
browsers: ['last 3 versions', '> 5%']
},
js = {
in: src + 'assets/javascripts/*.{js,coffee}',
out: dest + 'assets/javascripts/'
},
uglifyOpts = {
output: {
comments: 'uglify-save-license'
}
},
images = {
in: src + 'assets/images/*',
out: dest + 'assets/images/'
},
serverOpts = {
proxy: 'localhost:4567',
open: true,
reloadDelay: 700,
files: [dest + '**/*.{js,css}', src + '**/*.{html,haml,markdown}']
};
// 3. WORKER TASKS
// CSS Preprocessing
gulp.task('css', function() {
return gulp.src(css.in)
.pipe(development(p.sourcemaps.init()))
.pipe(p.sass(sassOpts).on('error', p.sass.logError))
.pipe(p.autoprefixer(autoprefixerOpts)).on('error', handleError)
.pipe(production(p.cleanCss()))
.pipe(development(p.sourcemaps.write()))
.pipe(gulp.dest(css.out));
});
// Javascript Bundling
gulp.task('js', function() {
var b = p.browserify({
entries: src + 'assets/javascripts/all.js',
debug: true
});
return b.bundle().on('error', handleError)
.pipe(p.source('bundle.js'))
.pipe(production() ? p.buffer() : p.noop())
.pipe(production(p.stripDebug()))
.pipe(production() ? p.uglify(uglifyOpts) : p.noop())
.pipe(gulp.dest(js.out));
});
// Image Optimization
gulp.task('images', function() {
return gulp.src(images.in)
.pipe(p.changed(images.out))
.pipe(p.imagemin())
.pipe(gulp.dest(images.out));
});
// Clean .tmp/
gulp.task('clean', function() {
p.del([
dest + '*'
]);
});
// Asset Size Report
gulp.task('sizereport', function () {
return gulp.src(dest + '**/*')
.pipe(p.sizereport({
gzip: true
}));
});
// 4. SUPER TASKS
// Development Task
gulp.task('development', function(done) {
p.runSequence('clean', 'css', 'js', 'images', done);
});
// Production Task
gulp.task('production', function(done) {
p.runSequence('clean', 'css', 'js', 'images', 'sizereport', done);
});
// Default Task
// This is the task that will be invoked by Middleman's exteranal pipeline when
// running 'middleman server'
gulp.task('default', ['development'], function() {
p.browserSync.init(serverOpts);
gulp.watch(css.in, ['css']);
gulp.watch(js.in, ['js']);
gulp.watch(images.in, ['images']);
});
function handleError(err) {
console.log(err.toString());
this.emit('end');
}