-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
199 lines (173 loc) · 5.17 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
'use strict';
const gulp = require('gulp');
const gulpLoadPlugins = require('gulp-load-plugins');
const browserSync = require('browser-sync').create();
const del = require('del');
const wiredep = require('wiredep').stream;
const run = require('run-sequence');
const browserify = require('gulp-browserify');
const fileinclude = require('gulp-file-include');
const minify = require('gulp-minify');
const cleanCSS = require('gulp-clean-css');
const $ = gulpLoadPlugins();
const reload = browserSync.reload;
var dev = false;
///////////////////////
//*
//* NOTE ON DIST VS SRC
//* I am moving away from having functions.php
//* be the src of which path we serve
//* always serve from dist and minify/other dist tasks
//* will be part of the build env. -DC
///////////////
gulp.task('runFileInclude', (callback) => {
run(['fileinclude'], () => {
callback();
});
});
gulp.task('fileinclude', () => {
gulp.src('templates/**/*.twig')
.pipe(fileinclude({
prefix: '@@',
basepath: '@file'
}))
.pipe(gulp.dest('.tmp/templates'));
});
gulp.task('styles', () => {
return gulp.src('./src/scss/main.scss')
.pipe($.plumber())
.pipe($.sourcemaps.init())
.pipe($.sass.sync({
outputStyle: 'expanded',
precision: 10,
includePaths: ['.']
}).on('error', $.sass.logError))
.pipe($.autoprefixer({browsers: ['> 1%', 'last 2 versions', 'Firefox ESR', 'iOS 7']}))
.pipe($.sourcemaps.write('dist/styles/'))
.pipe(gulp.dest('dist/styles/'))
.pipe(reload({stream: true}));
});
gulp.task('scripts', () => {
// Single entry point to browserify
gulp.src('src/js/main.js')
.pipe(browserify({
insertGlobals : true,
debug : !gulp.env.production
}))
.pipe(gulp.dest('./dist/browserify/'));
return gulp.src('src/js/**/*.js')
.pipe($.plumber())
.pipe($.sourcemaps.init())
.pipe($.babel())
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest('dist/scripts'))
.pipe(reload({stream: true}));
});
gulp.task('compress', function() {
gulp.src('./dist/browserify/*.js')
.pipe(minify({
ext:{
src:'-debug.js',
min:'.js'
},
exclude: ['tasks'],
ignoreFiles: ['.combo.js', '-min.js']
}))
.pipe(gulp.dest('./dist/browserify/'))
});
gulp.task('minify-css', function() {
return gulp.src('./dist/styles/main.css')
.pipe(cleanCSS({ compatibility: '*' }))
.pipe(gulp.dest('./dist/styles/'));
});
//take a stand airbnb
function lint(files, options) {
return gulp.src(files)
.pipe($.eslint({ fix: true }))
.pipe(reload({stream: true, once: true}))
.pipe($.eslint.format())
.pipe($.if(!browserSync.active, $.eslint.failAfterError()));
}
gulp.task('lint', () => {
return lint('src/js/**/*.js')
.pipe(gulp.dest('src/js'));
});
//lint test not configured
gulp.task('lint:test', () => {
return lint('test/spec/**/*.js')
.pipe(gulp.dest('test/spec'));
});
gulp.task('html', ['runFileInclude', 'styles', 'scripts'], () => {
return gulp.src('.tmp/**/*.twig')
.pipe($.useref({searchPath: ['.tmp', 'src', '.']}))
.pipe($.if('*.js', $.uglify()))
.pipe($.if('*.css', $.cssnano({safe: true, autoprefixer: false})))
.pipe($.if('*.twig', $.htmlmin({collapseWhitespace: true,includeAutoGeneratedTags:false})))
.pipe(gulp.dest('dist'));
});
gulp.task('images', () => {
return gulp.src('src/images/**/*')
.pipe($.cache($.imagemin()))
.pipe(gulp.dest('dist/images'));
});
gulp.task('fonts', () => {
return lint('src/fonts/')
.pipe(gulp.dest('dist/fonts'));
});
gulp.task('extras', () => {
return gulp.src([
'src/*',
'!src/*.twig'
], {
dot: true
}).pipe(gulp.dest('dist'));
});
gulp.task('clean', del.bind(null, ['.tmp', 'dist']));
gulp.task('serve', () => {
run(['clean', 'wiredep'], ['html', 'styles', 'scripts', 'images', 'fonts'], () => {
// TODO: update the proxy URL below.
browserSync.init({
notify: false,
proxy: 'http://theme.lndo.site/',
files: [
'**/*.css',
'**/*.js',
]
});
gulp.watch([
'src/images/**/*',
'dist/styles/**/*',
'dist/fonts/**/*'
]).on('change', reload);
// gulp.watch('templates/**/*.twig', ['runFileInclude', 'html']);
gulp.watch('src/scss/**/*.scss', ['styles']);
// gulp.watch('src/images/**/*'); // further define how this runs and when? cache? server only?
gulp.watch('src/js/**/*.js', ['scripts']);
// gulp.watch('src/fonts/**/*', ['fonts']);
// gulp.watch('bower.json', ['wiredep', 'fonts']);
});
});
// inject bower components
gulp.task('wiredep', () => {
gulp.src('app/styles/*.scss')
.pipe($.filter(file => file.stat && file.stat.size))
.pipe(wiredep({
ignorePath: /^(\.\.\/)+/
}))
.pipe(gulp.dest('src/styles'));
gulp.src('src/*.html')
.pipe(wiredep({
ignorePath: /^(\.\.\/)*\.\./
}))
.pipe(gulp.dest('./'));
});
gulp.task('build', ['html', 'images', 'fonts'], () => {
return gulp.src('dist/**/*').pipe($.size({title: 'build', gzip: true}));
});
gulp.task('production', ['compress', 'minify-css'])
gulp.task('default', () => {
return new Promise(resolve => {
dev = true;
run(['clean', 'wiredep'], 'build', resolve);
});
});