-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.babel.js
More file actions
151 lines (128 loc) · 4.21 KB
/
gulpfile.babel.js
File metadata and controls
151 lines (128 loc) · 4.21 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
/*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 gulprun = require('run-sequence');
const yargs = require('yargs');
const browserSync = require('browser-sync');
const wct = require('web-component-tester');
const filter = require('gulp-filter');
const lazypipe = require('lazypipe');
// HTML
const inline = require('gulp-inline-source');
const processInline = require('gulp-process-inline');
const minify = require('gulp-htmlmin');
// JS
const eslint = require('gulp-eslint');
const rollup = require('gulp-rollup-file');
const rollupif = require('rollup-plugin-conditional');
const resolve = require('rollup-plugin-node-resolve');
const commonJs = require('rollup-plugin-commonjs');
const babel = require('rollup-plugin-babel');
const uglify = require('rollup-plugin-uglify');
const uglifyHarmony = require('uglify-js-harmony').minify;
// CSS
const postcss = require('gulp-postcss');
const autoprefixer = require('autoprefixer');
const bs = browserSync.create(),
argv = yargs.boolean(['debug']).argv,
errorNotifier = () => plumber({ errorHandler: notify.onError('Error: <%= error.message %>') }),
OPTIONS = {
rollup: {
plugins: [
resolve({ main: true, browser: true }),
commonJs(),
babel({
exclude: 'node_modules/**/*'
}),
rollupif(!argv.debug, [
uglify({}, uglifyHarmony )
])
],
format: 'iife'
},
postcss: [
autoprefixer()
],
inline: {
compress: false,
swallowErrors: true
},
HTMLmin: {
removeComments: true,
removeCommentsFromCDATA: true,
collapseWhitespace: true,
conservativeCollapse: true,
caseSensitive: true,
keepClosingSlash: true,
customAttrAssign: [/\$=/],
minifyCSS: true,
minifyJS: false
},
browserSync: {
server: {
baseDir: './',
index: 'demo/index.html',
routes: {
'/': './bower_components'
}
},
open: false,
notify: false
}
};
const processJs = lazypipe()
.pipe(eslint)
.pipe(eslint.format)
.pipe(() => gulpif(!argv.debug, eslint.failAfterError()))
.pipe(rollup, OPTIONS.rollup);
gulp.task('build', () => {
let styles = processInline(),
scripts = processInline();
return gulp.src(['src/*.html'])
.pipe(errorNotifier())
// Inline assets
.pipe(inline(OPTIONS.inline))
// JS
.pipe(scripts.extract('script'))
.pipe(processJs())
.pipe(scripts.restore())
// CSS
.pipe(styles.extract('style'))
.pipe(postcss(OPTIONS.postcss))
.pipe(styles.restore())
.pipe(gulpif(!argv.debug, minify(OPTIONS.HTMLmin)))
.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(scripts.extract('script'))
.pipe(processJs())
.pipe(scripts.restore())
.pipe(js.restore)
.pipe(gulp.dest('.test'));
});
wct.gulp.init(gulp);
gulp.task('serve', () => bs.init(OPTIONS.browserSync));
gulp.task('refresh', () => bs.reload());
gulp.task('test', ['build', 'build:tests', 'test:local']);
gulp.task('watch:src', () => gulp.watch(['src/**/*'], () => gulprun('build', 'refresh')));
gulp.task('watch:tests', () => gulp.watch(['test/**/*'], () => gulprun('build:tests')))
gulp.task('watch', ['watch:src', 'watch:tests']);
gulp.task('default', ['build', 'build:tests', 'serve', 'watch']);