-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
78 lines (61 loc) · 2.07 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
const gulp = require('gulp');
const runSequence = require('run-sequence');
gulp.task('styles', () => {
const sass = require('gulp-sass');
const cleanCSS = require('gulp-clean-css');
const autoprefixer = require('gulp-autoprefixer');
return gulp.src('./source/stylesheets/main.sass')
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer({ browsers: ['last 2 versions'] }))
.pipe(gulp.dest('./dist/stylesheets'));
});
gulp.task('minify-styles', () => {
const cleanCSS = require('gulp-clean-css');
return gulp.src('./dist/stylesheets/main.css')
.pipe(cleanCSS())
.pipe(gulp.dest('./dist/stylesheets'));
});
gulp.task('style-helpers', () => {
const paths = ['functions', 'variables'];
const base = './source/stylesheets/';
const dist = './dist/stylesheets';
return paths.forEach((path) => {
let src = base + path + '/**/*';
gulp.src(src, { base: base }).pipe(gulp.dest(dist));
});
});
gulp.task('views', () => {
return gulp.src('./source/views/**/*').pipe(gulp.dest('./dist/views'));
});
gulp.task('images', () => {
const imagemin = require('gulp-imagemin');
return gulp.src('./source/images/**/*')
.pipe(imagemin())
.pipe(gulp.dest('./dist/images'))
});
gulp.task('scripts', () => {
return gulp.src('./source/javascripts/**/*').pipe(gulp.dest('./dist/javascripts'));
});
gulp.task('watch', () => {
require('gulp-livereload').listen();
gulp.watch('./source/stylesheets/**/*', ['styles']);
gulp.watch('./source/views/**/*', ['views']);
gulp.watch('./source/images/**/*', ['images']);
gulp.watch('./source/javascripts/**/*', ['scripts']);
});
gulp.task('serve', ['styles'], () => {
const browserSync = require('browser-sync').create();
browserSync.init({
port: 8000,
server: {
baseDir: './dist'
}
});
gulp.watch('./dist/**/*').on('change', browserSync.reload);
});
gulp.task('default', () => {
runSequence('styles', 'views', 'images', 'scripts', 'serve', 'watch');
});
gulp.task('build', () => {
runSequence('styles', 'views', 'images', 'scripts', 'minify-styles', 'style-helpers');
});