This repository was archived by the owner on May 16, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
executable file
·162 lines (145 loc) · 4.63 KB
/
Copy pathgulpfile.js
File metadata and controls
executable file
·162 lines (145 loc) · 4.63 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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
'use strict';
// Load dependencies
const autoprefixer = require('gulp-autoprefixer');
const browserSync = require('browser-sync').create();
const gulp = require('gulp');
const babel = require ('gulp-babel');
const cleanCss = require('gulp-clean-css');
const concat = require ('gulp-concat');
const eslint = require('gulp-eslint');
const compileHandlebars = require('gulp-compile-handlebars');
const imagemin = require ('gulp-imagemin');
const plumber = require('gulp-plumber');
const rename = require('gulp-rename');
const sass = require('gulp-sass');
const sourcemaps = require('gulp-sourcemaps');
const minify = require('gulp-minify');
const uglify = require('gulp-uglify');
// Load Handlebars variables
const { variables } = require('./variables.js')
const source = {
sass: './src/sass/custom/**/*.scss',
bootstrap: './src/sass/bootstrap/*.scss',
scripts: {
custom: './src/js/*.js',
vendor: './src/js/vendor/**/*.js'
},
images: './src/img/**/*',
assets: './src/assets/**/*',
};
const watch = {
sass: './src/sass/custom/**/*.scss',
bootstrap: './src/sass/bootstrap/*.scss',
scripts: {
custom: './src/js/*.js',
vendor: './src/js/vendor/**/*.js'
},
images: './src/img/**/*',
handlebars: './views/**/*.handlebars',
assets: './src/assets**/*',
};
const output = {
sass: './dist/assets/css',
bootstrap: './dist/assets/css/bootstrap',
scripts: './dist/assets/js',
images: './dist/img',
handlebars: './dist',
assets: './dist',
};
const handlebars = {
pages: {
index: {
path: './views/index.handlebars',
output: 'index.html',
templateData: variables,
}
},
options: {
batch: ['./views/partials']
},
output: './dist'
}
const imageSettings = [
imagemin.gifsicle({interlaced: true}),
imagemin.jpegtran({progressive: true}),
imagemin.optipng({optimizationLevel: 5}),
imagemin.svgo({
plugins: [
{removeViewBox: true},
{cleanupIDs: false}
]
})
];
const autoprefixerBrowsers = [
'ie >= 10',
'ie_mob >= 10',
'ff >= 30',
'chrome >= 34',
'safari >= 7',
'opera >= 23',
'ios >= 7',
'android >= 4.4',
'bb >= 10'
];
gulp.task('assets', () => {
return gulp.src(source.assets)
.pipe(gulp.dest(output.assets))
})
// Compile and automatically prefix stylesheets
gulp.task('sass', () => {
return gulp.src(source.sass)
.pipe(plumber())
.pipe(sourcemaps.init()) // Comment this line for production build
.pipe(sass())
.pipe(autoprefixer('last 2 versions'))
.pipe(cleanCss({compatibility: 'ie8'}))
.pipe(sourcemaps.write()) // Comment this line for production build
.pipe(gulp.dest(output.sass))
.pipe(browserSync.stream());
});
// Process all custom Javascript files
gulp.task('scripts-custom', () => {
return gulp.src(source.scripts.custom)
.pipe(plumber())
.pipe(sourcemaps.init()) // Comment this line for production build
.pipe(babel({presets: ['es2015']}))
.pipe(concat('main.min.js'))
.pipe(uglify())
.pipe(sourcemaps.write()) // Comment this line for production build
.pipe(gulp.dest(output.scripts));
});
// Process all vendor Javascript files
gulp.task('scripts-vendor', () => {
return gulp.src(source.scripts.vendor)
.pipe(gulp.dest(output.scripts));
});
// Image optimalisation
gulp.task('images', () => {
return gulp.src(source.images)
.pipe(imagemin(imageSettings))
.pipe(gulp.dest(output.images))
});
// Handlebars to html
gulp.task('handlebars', () => {
return gulp.src(handlebars.pages.index.path)
.pipe(compileHandlebars(handlebars.pages.index.templateData, handlebars.options))
.pipe(rename(handlebars.pages.index.output))
.pipe(gulp.dest(handlebars.output));
});
// Sets browsersync
gulp.task('serve', ['handlebars', 'sass', 'scripts-custom', 'scripts-vendor', 'images', 'assets'], () => {
browserSync.init({
server: {
baseDir: './dist'
}
});
gulp.watch(watch.sass, ['sass']);
//gulp.watch(watch.bootstrap, ['bootstrap']);
gulp.watch(watch.scripts.custom, ['scripts-custom']).on('change', browserSync.reload);
gulp.watch(watch.scripts.vendor, ['scripts-vendor']).on('change', browserSync.reload);
gulp.watch(watch.images, ['images']).on('change', browserSync.reload);
gulp.watch(watch.handlebars, ['handlebars']).on('change', browserSync.reload);
gulp.watch(watch.assets, ['assets']).on('change', browserSync.reload);
});
// Initialize default task
gulp.task('default', ['serve']);