forked from brianmontanaweb/performance-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.babel.js
More file actions
122 lines (111 loc) · 3.44 KB
/
gulpfile.babel.js
File metadata and controls
122 lines (111 loc) · 3.44 KB
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
/**
*
*
* This has been converted into my framework from WSK
* Not a lot is the same but I've kept the concept of WSK
*
*/
import gulp from 'gulp';
import del from 'del';
import runSequence from 'run-sequence';
import browserSync from 'browser-sync';
import gulpLoadPlugins from 'gulp-load-plugins';
import autoprefixer from 'autoprefixer';
const $ = gulpLoadPlugins();
// Optimize images, only looking at the main four. SVG, PNG, JPG and GIF. SVGs can be optimized further by the designer by reducing paths, etc
gulp.task('images', () => {
return gulp.src('app/images/**/*.{svg,png,jpg,gif}')
.pipe($.cache($.imagemin()))
.pipe(gulp.dest('dist/images'))
.pipe($.size({title: 'images'}));
});
// Copy all files at the root level (app)
gulp.task('copy', () => {
return gulp.src([
'app/*',
'app/*.html',
'node_modules/apache-server-configs/dist/.htaccess',
'!tmp-'
], {
dot: true
})
.pipe(gulp.dest('dist'))
.pipe($.size({title: 'copy'}));
});
//Run Sass Lint before compiling
//Checks setup of Sass files and confirms they match the standards
gulp.task('style-lint', () => {
return gulp.src('app/**/*.scss')
.pipe($.stylelint({
reporters: [
{formatter: 'string', console: true}
],
debug: true,
syntax: 'scss'
}))
});
// Compile and automatically prefix stylesheets, postCSS can be reviewed for less than modern browser fall backs
gulp.task('styles', () => {
// For best performance, don't add Sass partials to `gulp.src` just globby glob it
//Using postCSS cause it's p cool, right now just using autoprefixer after Sass is compiled
return gulp.src([
'app/**/*.scss',
'app/styles/**/*.css'
])
.pipe($.changed('.tmp/styles', {extension: '.css'}))
//Source maps work in Chrome to let you see what partial is being fetched
.pipe($.sourcemaps.init())
.pipe($.sass({
outputStyle: 'compressed'
}).on('error', $.sass.logError))
.pipe($.postcss([autoprefixer()]))
.pipe($.sourcemaps.write('./'))
.pipe(gulp.dest('dist'))
.pipe($.size({title: 'styles'}));
});
// Concatenate and minify JavaScript
gulp.task('scripts', () => {
return gulp.src(['./app/scripts/main.js'])
.pipe($.concat('main.min.js'))
.pipe($.uglify({preserveComments: 'some'}))
// Output files
.pipe(gulp.dest('dist/scripts'))
.pipe($.size({title: 'scripts'}));
});
// Scan your HTML for assets & optimize it
gulp.task('html', () => {
return gulp.src('dist/**/*.html')
// Minify any HTML
.pipe($.if('*.html', $.htmlmin()))
// Output files
.pipe(gulp.dest('dist'))
.pipe($.size({title: 'html'}));
});
// Clean output directory (dist/temp)
gulp.task('clean', cb =>
del(['.tmp', 'dist/*', '!dist/.git'],
{dot: true}, cb));
// Watch files for changes & reload
gulp.task('serve', () => {
runSequence('default');
browserSync.init({
server: {
baseDir: './dist'
}
});
//Each watch task is specific to how to control the direction of tasks
gulp.watch('app/scripts/*.js', ['scripts']);
gulp.watch('app/styles/**/*.scss', ['styles', 'style-lint']);
//Watch index for any changes to landing page and run scripts
gulp.watch('app/index.html', ['default']);
gulp.watch('app/**/*.html', ['html']);
gulp.watch('app/images/**/*.{svg,png,jpg,gif}', ['images']);
});
// Build production files, the default task
gulp.task('default', ['clean'], () => {
runSequence(
'styles',
'copy',
['scripts', 'html', 'images']
);
});