/
gulpfile.babel.js
132 lines (121 loc) · 2.51 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
'use strict';
/*
Imports
*/
import gulp from 'gulp';
import browserSync from 'browser-sync';
import pkg from './package.json';
import beeper from 'beeper';
import header from 'gulp-header';
import rename from 'gulp-rename';
import eslint from 'gulp-eslint';
import moment from 'moment';
import uglify from 'gulp-uglify';
import del from 'del';
import nodemon from 'nodemon';
import babel from 'gulp-babel';
/*
Paths
*/
const PATHS = {
SRC: 'src/simpleParallax.js',
DEST: 'dist/'
}
/*
Create header via package.json to add in JS and CSS media files
*/
const now = moment().format('DD-MM-YYYY H:m:s');
const banner = [
'/**',
' * <%= pkg.name %> - <%= pkg.description %>',
' * @version v<%= pkg.version %>',
' * @date: <%= now %>',
' * @link <%= pkg.homepage %>',
' */',
''
].join('\n');
/*
Error catcher
*/
export function onError(err) {
beeper(2);
console.log(err);
this.emit('end');
}
/*
Clear JS
*/
export function clearJS() {
return del(PATHS.DEST.js);
}
/*
build JS
*/
export const build = () =>
gulp
.src(PATHS.SRC)
.pipe(babel({
presets: ['env']
}))
.pipe(uglify())
.pipe(header(banner, { pkg: pkg, now: now }))
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest(PATHS.DEST))
.pipe(browserSync.reload({ stream: true }));
/*
ES Lint
*/
export const esLint = () =>
gulp
.src(['src/simpleParallax.js'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
/*
GULP server
*/
export const develop = () =>
nodemon({
script: './server.js',
ext: 'js',
watch: ['gulpfile.js', 'server.js'],
ignore: ['./node_modules/'],
env: {
NODE_ENV: 'development'
}
});
/*
GULP BROWSERSYNC
*/
export const launchBrowserSync = () =>
browserSync.init(null, {
proxy: 'http://localhost:3000',
browser: 'chrome',
port: 3001,
open: true,
browser: 'chrome',
logFileChanges: true,
logConnections: false,
injectChanges: true,
timestamps: false,
ghostMode: {
clicks: true,
forms: true,
scroll: false
}
});
/*
GULP Watch
*/
export const watch = () => {
gulp.watch(PATHS.SRC, { interval: 1000 }, build);
};
/*
TASK: Default
*/
const dev = gulp.series(
gulp.parallel(build),
gulp.parallel(launchBrowserSync, develop, watch)
);
gulp.task('dev', dev);
export default dev;