-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
134 lines (114 loc) · 3.81 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
/*eslint one-var: 0 */
// Core deps
// Use require() because of rollup
const gulp = require('gulp');
const notify = require('gulp-notify');
const gulpif = require('gulp-if');
const size = require('gulp-size');
const plumber = require('gulp-plumber');
const lazypipe = require('lazypipe');
const filter = require('gulp-filter');
const rename = require('gulp-rename');
const gulprun = require('run-sequence');
const yargs = require('yargs');
const browserSync = require('browser-sync');
const wct = require('web-component-tester');
// JS
const eslint = require('gulp-eslint');
const rollup = require('gulp-rollup-file');
const commonJs = require('rollup-plugin-commonjs');
const babel = require('rollup-plugin-babel');
const resolve = require('rollup-plugin-node-resolve');
const uglify = require('gulp-uglify');
const sourcemaps = require('gulp-sourcemaps');
// HTML
const inline = require('gulp-inline-source');
const processInline = require('gulp-process-inline');
const wctConfig = require('./wct.conf.js'),
bs = browserSync.create(),
argv = yargs.boolean(['debug']).argv,
errorNotifier = () => plumber({ errorHandler: notify.onError('Error: <%= error.message %>') }),
OPTIONS = {
rollup: {
plugins: [
resolve({
main: true,
jsnext: true,
browser: true,
}),
commonJs(),
babel()
],
format: 'iife'
},
uglify: {
mangle: !argv.debug
},
inline: {
compress: false,
swallowErrors: true
},
browserSync: {
server: {
baseDir: './',
index: 'demo/index.html',
routes: {
'/': './bower_components'
}
},
open: false,
notify: false
}
};
wct.gulp.init(gulp);
const processJs = lazypipe()
.pipe(() => gulpif(argv.debug, sourcemaps.init()))
.pipe(eslint)
.pipe(eslint.format)
.pipe(() => gulpif(!argv.debug, eslint.failAfterError()))
.pipe(rollup, OPTIONS.rollup)
.pipe(() => gulpif(!argv.debug, uglify(OPTIONS.uglify)))
.pipe(() => gulpif(argv.debug, sourcemaps.write()));
gulp.task('build', () => {
const js = filter((file) => /\.(js)$/.test(file.path), { restore: true }),
html = filter((file) => /\.(html)$/.test(file.path), { restore: true }),
scripts = processInline();
return gulp.src('src/*')
.pipe(errorNotifier())
.pipe(js)
.pipe(processJs())
.pipe(rename(path => path.extname = '.min.js'))
.pipe(js.restore)
.pipe(html)
.pipe(inline(OPTIONS.inline))
.pipe(scripts.extract('script:not([src])'))
.pipe(processJs())
.pipe(scripts.restore())
.pipe(html.restore)
.pipe(size({ gzip: true }))
.pipe(gulp.dest('.'))
});
gulp.task('build:tests', () => {
const js = filter((file) => /\.(js)$/.test(file.path), { restore: true }),
html = filter((file) => /\.(html)$/.test(file.path), { restore: true }),
scripts = processInline();
return gulp.src(['test/**/*'])
.pipe(errorNotifier())
.pipe(html)
.pipe(inline(OPTIONS.inline))
.pipe(scripts.extract('script'))
.pipe(processJs())
.pipe(scripts.restore())
.pipe(html.restore)
.pipe(js)
.pipe(processJs())
.pipe(js.restore)
.pipe(gulp.dest('.test'));
});
gulp.task('watch:src', () => gulp.watch(['src/**/*'], () => gulprun('build', 'refresh')));
gulp.task('watch:tests', () => gulp.watch(['test/**/*', 'src/**/*'], ['build:tests']));
gulp.task('watch', [ 'watch:src', 'watch:tests' ]);
gulp.task('serve', () => bs.init(OPTIONS.browserSync));
gulp.task('refresh', () => bs.reload());
gulp.task('test', () => gulprun('build', 'build:tests', 'test:local'));
gulp.task('default', ['build', 'serve', 'watch']);