This repository has been archived by the owner on Aug 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
150 lines (122 loc) · 3.33 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
146
147
148
149
150
// gulpfile.js - https://jsua.co/mm-gulp
'use strict'; // http://www.w3schools.com/js/js_strict.asp
// 1. LOAD PLUGINS
const gulp = require('gulp');
const bourbon = require('bourbon').includePaths;
const neat = require('bourbon-neat').includePaths;
const sass = require('gulp-sass')(require('node-sass'));
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',
'gulp-util': 'gutil'
},
});
// 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 = {
},
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', (cb) => {
gulp.src(css.in)
.pipe(development(p.sourcemaps.init()))
.pipe(sass(sassOpts).on('error', sass.logError))
.pipe(p.autoprefixer(autoprefixerOpts)).on('error', handleError)
.pipe(production(p.cleanCss()))
.pipe(development(p.sourcemaps.write()))
.pipe(gulp.dest(css.out));
cb();
});
// Javascript Bundling
gulp.task('js', (cb) => {
var b = p.browserify({
entries: src + 'assets/javascripts/all.js',
debug: true
});
b.bundle().on('error', handleError)
.pipe(p.source('bundle.js'))
.pipe(production() ? p.buffer() : p.gutil.noop())
.pipe(production(p.stripDebug()))
.pipe(production() ? p.uglify(uglifyOpts) : p.gutil.noop())
.pipe(gulp.dest(js.out));
cb();
});
// Image Optimization
gulp.task('images', (cb) => {
console.log('images');
gulp.src(images.in)
.pipe(p.changed(images.out))
.pipe(p.imagemin())
.pipe(gulp.dest(images.out));
cb();
});
// Clean .tmp/
gulp.task('clean', function(done) {
p.del([
dest + '*'
]);
done();
});
// Asset Size Report
gulp.task('sizereport', (cb) => {
gulp.src(dest + '**/*')
.pipe(p.sizereport({
gzip: true
}));
cb();
});
// 4. SUPER TASKS
// Development Task
gulp.task('development', gulp.series(
'clean', 'images', 'css', 'js'
));
// Production Task
gulp.task('production', gulp.series('clean', 'images', 'css', 'js', 'sizereport'));
// Default Task
// This is the task that will be invoked by Middleman's exteranal pipeline when
// running 'middleman server'
gulp.task('default', gulp.series('development', () => {
p.browserSync.init(serverOpts);
gulp.watch(images.in, gulp.task('images'));
gulp.watch(css.in, gulp.task('css'));
gulp.watch(js.in, gulp.task('js'));
}));
function handleError(err) {
console.log(err.toString());
this.emit('end');
}