-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gulpfile.js
127 lines (116 loc) · 3.94 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
const gulp = require('gulp');
// Include Plugins
const autoprefixer = require('gulp-autoprefixer');
const babel = require('gulp-babel');
const browserSync = require('browser-sync').create();
const concat = require('gulp-concat');
const gutil = require('gulp-util');
const imagemin = require('gulp-imagemin');
const imageResize = require('gulp-image-resize');
const minifycss = require('gulp-minify-css');
const os = require('os');
const parallel = require("concurrent-transform");
const plumber = require('gulp-plumber');
const postcss = require('gulp-postcss');
const rename = require('gulp-rename');
const sass = require('gulp-sass');
const sassdoc = require('sassdoc');
const sassFiles = 'scss/**/*.scss';
const sourcemaps = require('gulp-sourcemaps');
const uglify = require('gulp-uglify');
gulp.task('sassdoc', function() {
var options = {
dest: 'docs',
verbose: true,
basePath: 'https://github.com/rdwatters/gulp-starter/tree/master/scss'
};
return gulp.src('scss/**/*.scss')
.pipe(sassdoc(options));
});
// .pipe(errorHandler())
gulp.task('sass', () => {
return gulp.src(sassFiles)
.pipe(sourcemaps.init())
.pipe(sass({ outputStyle: 'expanded' }).on('error', sass.logError))
.pipe(autoprefixer())
.pipe(gulp.dest('css/'))
.pipe(minifycss())
.pipe(rename('style.min.css'))
.pipe(sourcemaps.write('css/'))
.pipe(gulp.dest('css/'));
});
// Concatenate & Minify JS
// .pipe(plumber())
gulp.task('scripts', function() {
return gulp.src('js/scripts/*js')
.pipe(sourcemaps.init())
.pipe(concat('main.js'))
.pipe(gulp.dest('js'))
.pipe(babel({
presets: ['es2015']
}))
.on('error', function(e) {
console.log('>>> ERROR', e);
// emit here
this.emit('end');
})
.pipe(uglify())
.pipe(rename('main.min.js'))
.pipe(sourcemaps.write())
.pipe(gulp.dest('js'));
});
gulp.task("image-resize", function() {
return gulp.src("source-images/*.{jpg,png,jpeg}")
.pipe(imagemin())
.pipe(parallel(
imageResize({ width: 1200 }),
os.cpus().length
))
.pipe(gulp.dest("images"))
.pipe(parallel(
imageResize({ width: 600 }),
os.cpus().length
))
.pipe(gulp.dest("images/half"))
.pipe(parallel(
imageResize({ width: 200 }),
os.cpus().length
))
.pipe(gulp.dest("images/thumbs"));
});
//browser-sync setup--will become your default task
gulp.task('serve', ['sass', 'scripts', 'image-resize', 'sassdoc'], function() {
browserSync.init({
server: {
baseDir: "./"
},
open: true
});
gulp.watch(['scss/*.scss', 'scss/**/*scss'], ['sass', 'sassdoc']);
gulp.watch("js/scripts/*.js", ['scripts']);
gulp.watch("*.html").on('change', browserSync.reload);
gulp.watch("source-images/*.{jpg,png,jpeg}", ['image-resize']);
gulp.watch("js/main.min.js").on('change', browserSync.reload);
// watch css and stream to BrowserSync when it changes
gulp.watch('css/style.min.css', function() {
gulp.src('css/style.min.css')
.pipe(browserSync.stream());
});
});
// Default Task
gulp.task('default', ['serve']);
gulp.task('images', ['image-resize']);
// custom error handler used in 'scripts'
// const errorHandler = function() {
// // default appearance
// return gplumber(function(error) {
// // add indentation
// var msg = error.codeFrame.replace(/\n/g, '\n ');
// // output styling
// gutil.log('|- ' + gutil.colors.bgRed.bold('Build Error in ' + error.plugin));
// gutil.log('|- ' + gutil.colors.bgRed.bold(error.message));
// gutil.log('|- ' + gutil.colors.bgRed('>>>'));
// gutil.log('|\n ' + msg + '\n |');
// gutil.log('|- ' + gutil.colors.bgRed('<<<'));
// });
// };