-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
166 lines (137 loc) · 4.28 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
165
166
'use strict';
// generated on 2014-07-14 using generator-gulp-webapp 0.1.0
// modified by AAT—C July 21 2015
var gulp = require('gulp');
var postcss = require('gulp-postcss');
var scss = require('postcss-scss');
var autoprefixer = require('gulp-autoprefixer');
var flexboxfixer = require('postcss-flexboxfixer');
// load plugins
var $ = require('gulp-load-plugins')(),
sass = require('gulp-sass'),
neat = require('node-neat').includePaths,
browserSync = require('browser-sync'),
reload = browserSync.reload,
gutil = require('gulp-util'),
filter = require('gulp-filter'),
plumber = require('gulp-plumber'),
php = require('gulp-connect-php'),
concat = require('gulp-concat');
var paths = {
scss: './app/assets/scss/*.scss',
js: './app/assets/scripts/*.js',
// images: './source/assets/images/*',
// fonts: './source/assets/fonts/*'
};
gulp.task('styles', function(){
var processors = [autoprefixer, flexboxfixer];
return gulp.src(paths.scss)
.pipe(sass({
includePaths: require('node-neat').includePaths.concat(neat)
}))
.pipe(postcss(processors, {syntax: scss}))
.pipe($.csso())
.pipe(gulp.dest('./app/assets/css/'))
.pipe($.size())
.pipe(reload({stream:true}));
});
gulp.task('scripts', function(){
return gulp.src(paths.js)
.pipe($.jshint())
.pipe($.jshint.reporter(require('jshint-stylish')))
.pipe($.uglify())
.pipe(concat('main.min.js'))
.pipe(gulp.dest('./app/assets/scripts'))
.pipe($.size())
.pipe(reload({stream:true}));
});
gulp.task('scripts-build', function(){
return gulp.src('./app/assets/scripts/vendor/*.js')
.pipe($.uglify())
.pipe(concat('all.js'))
.pipe(gulp.dest('./app/assets/scripts'))
.pipe($.size());
});
gulp.task('images', function () {
return gulp.src('app/assets/images/**/*')
.pipe($.cache($.imagemin({
optimizationLevel: 8,
progressive: true,
interlaced: true
})))
.pipe(gulp.dest('dist/assets/images'))
.pipe($.size());
});
gulp.task('fonts', function () {
return gulp.src(mainBowerFiles())
.pipe($.filter('**/*.{eot,svg,ttf,woff}'))
.pipe($.flatten())
.pipe(gulp.dest('dist/assets/fonts'))
.pipe($.size());
});
gulp.task('content', ['styles', 'scripts'], function () {
var jsFilter = $.filter('**/*.js');
var cssFilter = $.filter('**/*.css');
return gulp.src('app/**/*.php')
.pipe($.useref.assets({searchPath: '{.tmp,app}'}))
.pipe(jsFilter)
.pipe($.uglify())
.pipe(jsFilter.restore())
.pipe(cssFilter)
.pipe($.csso())
.pipe(cssFilter.restore())
.pipe($.useref.restore())
.pipe($.useref())
.pipe(gulp.dest('dist'))
.pipe($.size());
});
gulp.task('build', ['styles', 'scripts', 'images', 'fonts']);
gulp.task('default', function () {
// gulp.start('build');
console.log('Please choose build, watch, or serve');
});
gulp.task('php', function() {
php.server({
hostname: '127.0.0.1',
base: 'app',
port: 8000,
keepalive: true
});
});
gulp.task('serve', ['php','styles', 'scripts'], function () {
browserSync({
proxy: '127.0.0.1:8000',
port: 9090,
open: true,
notify: true
});
});
// inject bower components
gulp.task('wiredep', function () {
var wiredep = require('wiredep').stream;
gulp.src('app/assets/scss/**/*.scss')
.pipe(wiredep({
directory: '../bower_components'
}))
.pipe(gulp.dest('app/assets/css'));
gulp.src('app/**/*.php')
.pipe(wiredep({
directory: '../bower_components'
}))
.pipe(gulp.dest('app'));
});
// gulp.task('watch', ['connect', 'serve'], function () {
gulp.task('watch', ['serve'], function () {
// watch for changes
gulp.watch([
'app/**/*.php',
'app/assets/images/**/*',
'app/assets/scss/**/*.scss',
// 'app/content/**/*'
], reload);
gulp.watch('app/assets/scss/**/*.scss', ['styles']);
gulp.watch('app/assets/scripts/**/*.js', ['scripts']);
gulp.watch('app/assets/images/**/*', ['images']);
// gulp.watch('app/content/**/*', ['content']);
gulp.watch('bower.json', ['wiredep']);
});