-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
164 lines (147 loc) · 3.99 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
'use strict';
// Load modules
var browserSync = require('browser-sync');
var del = require('del');
var gulp = require('gulp');
var RevAll = require('gulp-rev-all');
var runSequence = require('run-sequence');
var _ = require('underscore');
// Gulp plugin to make loading further plugins trivial
var $ = require('gulp-load-plugins')();
// Load configuration from Laravel's dotenv file
require('dotenv').load();
// Override default configuration with that of our app's dotenv file
var config = _.extend({
environment: 'local',
url: 'http://webcomm.dev'
}, {
environment: process.env.APP_ENV,
url: process.env.APP_URL
});
// Function to determine if we are in production mode or not
function isProduction() {
return config.environment === 'production';
}
// Fonts
gulp.task('fonts', function () {
return gulp
.src('bower_components/font-awesome/fonts/*.{eot,svg,ttf,woff}')
.pipe(gulp.dest('public/assets/fonts'))
.pipe(browserSync.reload({
stream: true,
once: true
}));
});
// Images
gulp.task('images', function () {
return gulp
.src('app/assets/images/*')
.pipe($.if(isProduction(), $.imagemin({
optimizationLevel: 3,
progressive: true,
interlaced: true
})))
.pipe(gulp.dest('public/assets/images'))
.pipe(browserSync.reload({
stream: true,
once: true
}));
});
// Manifest
gulp.task('manifest', function () {
if (isProduction()) {
var revAll = new RevAll();
return gulp
.src([
'public/assets/javascripts/app.js',
'public/assets/stylesheets/app.css'
])
.pipe(revAll.revision())
.pipe(gulp.dest('public/assets'))
.pipe(revAll.manifestFile())
.pipe(gulp.dest('public/assets'));
}
});
// JavaScripts
gulp.task('javascripts', function () {
return gulp
.src([
'bower_components/zepto/zepto.js',
'bower_components/fastclick/lib/fastclick.js',
'app/assets/javascripts/app.js'
])
.pipe($.concat('app.js'))
.pipe($.if(isProduction(), $.uglify()))
.pipe(gulp.dest('public/assets/javascripts'))
.pipe(browserSync.reload({
stream: true
}))
.pipe($.notify('Compiled JavaScripts.'))
});
gulp.task('pages', function () {
return gulp
.src('app/index.php')
.pipe(gulp.dest('public'))
.pipe(browserSync.reload({
stream: true
}))
.pipe($.notify('Copied pages.'));
});
// Stylesheets
gulp.task('stylesheets', function () {
return gulp
.src('app/assets/stylesheets/app.scss')
.pipe($.sass({
sourceComments: !isProduction(),
includePaths: [
'bower_components/font-awesome/scss',
'bower_components/foundation/scss'
]
}))
.on('error', $.notify.onError())
.pipe($.if(isProduction(), $.uncss({
html: [config.url]
})))
.pipe($.if(isProduction(), $.minifyCss()))
.pipe($.autoprefixer('last 2 versions'))
.pipe(browserSync.reload({
stream: true
}))
.pipe(gulp.dest('public/assets/stylesheets'))
.pipe($.notify('Compiled Stylesheets.'));
});
// Clean
gulp.task('clean', function () {
del.sync([
'public/assets/fonts',
'public/assets/images',
'public/assets/javascripts',
'public/assets/rev-manifest.json',
'public/assets/stylesheets',
'public/index.php'
]);
});
// Serve task (for BrowserSync)
gulp.task('serve', function () {
return browserSync({
proxy: config.url,
port: 2015
});
});
// Default task
gulp.task('default', ['clean'], function () {
runSequence(
['fonts', 'images', 'javascripts', 'stylesheets'],
'manifest',
'pages'
);
gulp.start('fonts', 'images', 'javascripts', 'pages', 'stylesheets');
});
// Watch task will reload assets and proxy through livereload
gulp.task('watch', ['serve'], function () {
// Trigger compilation on asset changes
gulp.watch('app/index.php', ['pages']);
gulp.watch('app/assets/images/*', ['images']);
gulp.watch('app/assets/javascripts/*', ['javascripts']);
gulp.watch('app/assets/stylesheets/**/*', ['stylesheets']);
});