-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
88 lines (72 loc) · 2.14 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
var gulp = require('gulp');
const imagemin = require('gulp-imagemin');
let uglify = require('gulp-uglify-es').default;
var sass = require('gulp-sass');
var concat = require('gulp-concat');
var autoprefixer = require('gulp-autoprefixer');
const htmlPartial = require('gulp-html-partial');
var htmlmin = require('gulp-htmlmin');
var browserSync = require('browser-sync').create();
var reload = browserSync.reload;
var autoprefixerOptions = {
browsers: ['last 2 versions', '> 5%', 'Firefox ESR'] };
// Logs message
gulp.task('message', function() {
return console.log('Gulp is running....');
});
// Browser Sync
gulp.task('browser-sync', ['sass'], function() {
browserSync.init({
server: {
baseDir: "dist"
}
});
gulp.watch("src/sass/*.scss", ['sass']);
gulp.watch("src/**/*.html").on('change', reload);
});
// Complile Partials, Copy and minify all html files
gulp.task('copyhtml', function() {
gulp.src('src/**/*.html')
.pipe(htmlPartial({
basePath: 'src/partials/'
}))
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest('dist'));
});
// Optimize images
gulp.task('imageMin', () =>
gulp.src('src/images/*')
.pipe(imagemin())
.pipe(gulp.dest('dist/images'))
);
// Compress JavaScript
gulp.task('minify', function() {
gulp.src('src/js/*.js')
.pipe(uglify())
.pipe(gulp.dest('dist/js'))
});
// Compile Sass
gulp.task('sass', function() {
gulp.src('src/sass/**/*.scss')
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(autoprefixer(autoprefixerOptions))
.pipe(concat('style.css'))
.pipe(gulp.dest('dist/css'))
.pipe(reload({stream: true}));
});
// Concat Javascript
gulp.task('scripts', function() {
gulp.src('src/js/*.js')
// .pipe(concat('main.js'))
.pipe(uglify())
.pipe(gulp.dest('dist/js'));
});
// Run ALL tasks
gulp.task('default', ['message', 'copyhtml', 'imageMin', 'sass', 'scripts', 'browser-sync']);
// Watch Gulp tasks
gulp.task('watch', ['browser-sync'], function() {
gulp.watch('src/js/*.js', ['scripts']);
gulp.watch('src/images/*', ['imageMin']);
gulp.watch('src/sass/**/*.scss', ['sass']);
gulp.watch('src/**/*.html', ['copyhtml']);
});