forked from nk-o/jarallax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
131 lines (120 loc) · 2.87 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
const gulp = require('gulp');
const $ = require('gulp-load-plugins')();
const del = require('del');
const path = require('path');
const fs = require('fs');
const browserSync = require('browser-sync');
const named = require('vinyl-named');
const webpack = require('webpack-stream');
const webpackconfig = require('./webpack.config.js');
const qunit = require('node-qunit-phantomjs');
const data = require('json-file').read('./package.json').data;
function getMainHeader() {
return `/*!
* Name : Just Another Parallax [Jarallax]
* Version : ${data.version}
* Author : ${data.author}
* GitHub : ${data.homepage}
*/
`;
}
function getVideoHeader() {
return `/*!
* Name : Video Background Extension for Jarallax
* Version : 1.0.1
* Author : ${data.author}
* GitHub : ${data.homepage}
*/
`;
}
function getElementHeader() {
return `/*!
* Name : Elements Extension for Jarallax
* Version : 1.0.0
* Author : ${data.author}
* GitHub : ${data.homepage}
*/
`;
}
/**
* Error Handler for gulp-plumber
*/
function errorHandler(err) {
console.error(err);
this.emit('end');
}
/**
* Clean Task
*/
gulp.task('clean', () => del(['dist']));
/**
* JS Task
*/
gulp.task('js', () => {
return gulp.src(['src/*.js', '!src/*.esm.js'])
.pipe($.plumber({ errorHandler }))
.pipe(named())
.pipe(webpack({
config: webpackconfig,
}))
.pipe($.if(file => file.path.match(/jarallax.js$/), $.header(getMainHeader())))
.pipe($.if(file => file.path.match(/jarallax-video.js$/), $.header(getVideoHeader())))
.pipe($.if(file => file.path.match(/jarallax-element.js$/), $.header(getElementHeader())))
.pipe(gulp.dest('dist'))
.pipe($.rename({ suffix: '.min' }))
.pipe($.uglify({
output: {
comments: /^!/,
},
}))
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest('dist'))
.pipe(browserSync.stream());
});
/**
* CSS Task
*/
gulp.task('css', () => {
return gulp.src('src/*.css')
.pipe(gulp.dest('dist'))
.pipe(browserSync.stream());
});
/**
* BrowserSync Task
*/
gulp.task('browser_sync', () => {
browserSync.init({
server: {
baseDir: ['demo', './'],
},
});
});
/**
* Watch Task
*/
gulp.task('dev', () => {
$.sequence('browser_sync', 'build', () => {
gulp.watch('src/*.js', ['js']);
gulp.watch('src/*.css', ['css']);
});
});
/**
* Build (default) Task
*/
gulp.task('build', (cb) => {
$.sequence('clean', ['js', 'css'], cb);
});
gulp.task('default', ['build']);
/**
* Test Task
*/
gulp.task('test', ['build'], () => {
qunit('./tests/index.html', {
page: {
viewportSize: { width: 1280, height: 800 },
},
'phantomjs-options': ['--local-to-remote-url-access=true'],
// verbose: true,
timeout: 15,
});
});