-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
99 lines (90 loc) · 2.46 KB
/
Copy pathgulpfile.js
File metadata and controls
99 lines (90 loc) · 2.46 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
/**
* Gulp Dependencies
*/
const gulp = require('gulp');
const imagemin = require('gulp-imagemin');
const sass = require('gulp-sass');
const concat = require('gulp-concat');
const html2pug = require('gulp-html2pug');
const babel = require('gulp-babel');
const uglify = require('gulp-uglify');
const htmlmin = require('gulp-htmlmin');
const browserSync = require('browser-sync').create();
const rename = require("gulp-rename");
const sourcemaps = require('gulp-sourcemaps');
/**
* Location Constants
*/
// Inputs
const sassIn = 'app/sass/**/*.sass';
const es6In = 'app/js/**/*.js';
const imagesIn = 'app/images/**/*';
const htmlIn = 'app/*.html';
// Outputs
const sassOutDev = 'app/css';
const sassOutProd = 'app/build/css';
const es6OutDev = 'app/js';
const es6OutProd = 'app/build/js';
const imagesOut = 'app/build/images';
const htmlOut = 'app/build';
/**
* Compile, minify and concatenate sass files
*/
gulp.task('compile-sass', () => {
gulp.src(sassIn)
.pipe(sass({ outputStyle: 'compressed' }))
.pipe(concat('styles.bundle.css'))
.pipe(gulp.dest(sassOutDev))
.pipe(gulp.dest(sassOutProd))
.pipe(browserSync.stream());
});
/**
* Compile, minify and concatenate es6 files
*/
gulp.task('compile-es6', () => {
gulp.src([es6In, '!app/js/main.bundle.js']) // Don't recompile bundle
.pipe(sourcemaps.init())
.pipe(babel({ presets: ['es2015'] }))
.pipe(uglify())
.pipe(concat('main.bundle.js'))
.pipe(sourcemaps.write())
.pipe(gulp.dest(es6OutDev))
.pipe(gulp.dest(es6OutProd))
.pipe(browserSync.stream());
});
/**
* Optimize images
*/
gulp.task('minify-images', () => {
gulp.src(imagesIn)
.pipe(imagemin())
.pipe(gulp.dest(imagesOut))
.pipe(browserSync.stream());
});
/**
* Compile views to pug
*/
gulp.task('pug', () => {
gulp.src(htmlIn)
.pipe(htmlmin({ collapseWhitespace: true, removeComments: true }))
.pipe(html2pug())
.pipe(gulp.dest(htmlOut));
});
/**
* Monitor files for changes
*/
gulp.task('watch-files', () => {
browserSync.init({
server: {
baseDir: './app',
index: 'homepage.html'
}
});
gulp.watch(sassIn, ['compile-sass']);
gulp.watch(es6In, ['compile-es6']);
gulp.watch(imagesIn, ['minify-images']);
gulp.watch(htmlIn, ['pug']);
gulp.watch(htmlIn).on('change', browserSync.reload);
});
gulp.task('build', ['compile-sass', 'compile-es6', 'minify-images', 'pug']);
gulp.task('default', ['watch-files']);