-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
151 lines (135 loc) · 3.56 KB
/
gulpfile.babel.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
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
const gulp = require('gulp');
const handlebars = require('gulp-compile-handlebars');
const browserify = require('browserify');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const uglify = require('gulp-uglify');
const sourcemaps = require('gulp-sourcemaps');
const livereload = require('gulp-livereload');
const connect = require('gulp-connect');
const rename = require('gulp-rename');
const sass = require('gulp-sass');
const concat = require('gulp-concat');
const environments = require('gulp-environments');
const Tasks = Object.freeze({
BUILD: 'build',
PAGES: 'pages',
SCRIPTS: 'scripts',
STYLES: 'styles',
DEFAULT: 'default',
ICONS: 'icons',
IMAGES: 'images',
WATCH: 'watch',
SERVER: 'server'
});
const Paths = Object.freeze({
SRC: './index.js',
SOURCE: './index.js',
DIST: './build',
MAPS: './maps',
SCRIPTS: './src/**/*.js',
STYLES: ['assets/styles/*.scss', 'assets/styles/**/*.scss'],
STYLE_DIST: 'assets/style.css',
PARTIALS_DIR: './src/partials',
PARTIALS: './src/partials/*.hbs',
MAIN_FILES: './src/views/*.hbs',
ICONS_SOURCE: 'assets/icons/*.png',
ICONS_DIST: './build/assets/icons/',
IMAGES_SOURCE: 'assets/images/*.png',
IMAGES_DIST: './build/assets/images/',
MAIN_STYLE_FILE: 'assets/styles/main.scss',
DIST_FILE: 'index.html',
});
const BabelConfig = Object.freeze({
only: /^(?:.*\/node_modules\/(?:a|b)\/|(?!.*\/node_modules\/)).*$/,
presets: ['es2015'],
plugins: ['transform-object-rest-spread'],
global: true
});
const BrowserifyConfig = Object.freeze({
entries: Paths.SRC,
debug: true
});
const Transforms = Object.freeze({
BABELIFY: 'babelify'
});
gulp.task(Tasks.PAGES, function () {
const data = {
title: 'Salsa Jobs',
isProduction: environments.production(),
jobsUrl: environments.production()
? 'https://sauce-jobs-production.herokuapp.com/jobs'
: 'https://sauce-jobs-staging.herokuapp.com/jobs'
};
const options = {
batch : [ Paths.PARTIALS_DIR ],
helpers : {
capitals : function(str){
return str.toUpperCase();
}
}
};
return gulp.src(Paths.MAIN_FILES)
.pipe(handlebars(data, options))
.pipe(rename({
extname: '.html'
}))
.pipe(gulp.dest(Paths.DIST));
});
gulp.task(Tasks.SCRIPTS, function () {
return browserify(BrowserifyConfig)
.transform(Transforms.BABELIFY, BabelConfig)
.bundle()
.pipe(source(Paths.SOURCE))
.pipe(buffer())
.pipe(sourcemaps.init())
.pipe(uglify())
.pipe(sourcemaps.write(Paths.MAPS))
.pipe(gulp.dest(Paths.DIST));
});
gulp.task(Tasks.STYLES, function() {
return gulp.src(Paths.MAIN_STYLE_FILE)
.pipe(sass())
.pipe(concat(Paths.STYLE_DIST))
.pipe(gulp.dest(Paths.DIST));
});
gulp.task(Tasks.ICONS, function() {
return gulp.src(Paths.ICONS_SOURCE)
.pipe(gulp.dest(Paths.ICONS_DIST));
});
gulp.task(Tasks.IMAGES, function() {
return gulp.src(Paths.IMAGES_SOURCE)
.pipe(gulp.dest(Paths.IMAGES_DIST));
});
gulp.task(Tasks.BUILD, [
Tasks.PAGES,
Tasks.ICONS,
Tasks.IMAGES,
Tasks.SCRIPTS,
Tasks.STYLES
]);
gulp.task(Tasks.WATCH, [ Tasks.BUILD ], function () {
livereload.listen();
gulp.watch(
[
Paths.SOURCE,
Paths.SCRIPTS,
Paths.STYLES,
Paths.PARTIALS,
Paths.MAIN_FILES
],[
Tasks.BUILD
]
);
});
gulp.task(Tasks.SERVER, function() {
connect.server({
root: './build',
port: 5000
});
});
gulp.task(Tasks.DEFAULT, [
Tasks.BUILD,
Tasks.SERVER,
Tasks.WATCH
]);