forked from GoogleChromeLabs/ui-element-samples
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
112 lines (100 loc) · 2.81 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
'use strict';
const gulp = require('gulp');
const sass = require('gulp-sass');
const browserSync = require('browser-sync');
const imagemin = require('gulp-imagemin');
const sourcemaps = require('gulp-sourcemaps');
const postcss = require('gulp-postcss');
const autoprefixer = require('autoprefixer');
const notify = require('gulp-notify');
const useref = require('gulp-useref');
const uglify = require('gulp-uglify');
const gulpIf = require('gulp-if');
const del = require('del');
//Handles html files
gulp.task('html', function () {
//Takes all html files except index.html
return gulp.src('app/*.html')
.pipe(gulp.dest('.'))
.pipe(browserSync.reload({
stream: true
}));
});
//Converts SCSS to compressed CSS with gulp-sass
gulp.task('sass', function () {
return gulp.src('app/scss/main.scss')
.pipe(sourcemaps.init())
.pipe(sass({
outputStyle: 'nested'
})
.on('error', notify.onError(function (err) {
return {
title: 'u got an error',
message: err.message
};
})))
.pipe(postcss([autoprefixer({
browsers: ['last 2 versions']
})]))
.pipe(sourcemaps.write())
.pipe(gulp.dest('dist/css'))
.pipe(browserSync.reload({
stream: true
}));
});
//Handle js files
gulp.task('useref', function () {
return gulp.src('app/*.html')
.pipe(useref())
.pipe(gulpIf('*.js', uglify()))
.pipe(gulp.dest('.'))
.pipe(browserSync.reload({
stream: true
}));
});
//Optimizes images with no-repeating
gulp.task('images', function () {
return gulp.src('app/images/**/*.+(png|jpg|jpeg|gif|svg)')
.pipe(gulp.dest('dist/images'))
.pipe(browserSync.reload({
stream: true
}));
});
//Copy normalize.css
gulp.task('normalize', function () {
return gulp.src('app/scss/normalize.css')
.pipe(gulp.dest('dist/css'))
.pipe(browserSync.reload({
stream: true
}));
});
gulp.task('watch', function () {
gulp.watch('app/*.html', gulp.series('html', 'useref'))
gulp.watch('app/scss/**/*.scss', gulp.series('sass'))
gulp.watch('app/scripts/**/*.js', gulp.series('useref'))
gulp.watch('app/images/**/*.+(png|jpg|jpeg|gif|svg)', gulp.series('images'));
});
//Spins up a web server with live-reloading
gulp.task('serve', function () {
browserSync.init({
server: '.'
});
});
//Cleans up build folder
gulp.task('clean', function () {
del('dist');
return del('index.html');
});
//Build task
gulp.task('build', gulp.series(
'clean', 'html',
gulp.parallel('normalize', 'sass', 'useref', 'images')));
//Default gulp task
gulp.task('default',
gulp.series('build', gulp.parallel('watch', 'serve'))
);
// gulp.task('hash', function() {
// return gulp.src(['**/*.html', 'dist/**/*.css'])
// .pipe(hash_src({build_dir: 'dist', src_path: 'dist'}))
// .pipe(gulp.dest('hash'))
// });