-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.babel.js
116 lines (99 loc) · 3.14 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
/*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');
// 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 resolve = require('rollup-plugin-node-resolve');
const commonJs = require('rollup-plugin-commonjs');
const babel = require('rollup-plugin-babel');
const json = require('rollup-plugin-json');
// 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(),
json(),
babel({
exclude: 'node_modules/**/*'
})
],
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: true
},
browserSync: {
server: {
baseDir: './',
index: 'demo/index.html',
routes: {
'/': './bower_components'
}
},
open: false,
notify: false
}
};
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(eslint())
.pipe(eslint.format())
.pipe(gulpif(!argv.debug, eslint.failAfterError()))
.pipe(rollup(OPTIONS.rollup))
.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('.'))
});
wct.gulp.init(gulp);
gulp.task('serve', () => bs.init(OPTIONS.browserSync));
gulp.task('refresh', () => bs.reload());
gulp.task('test', ['build', 'test:local']);
gulp.task('watch', () => gulp.watch(['src/**/*'], () => gulprun('build', 'refresh')));
gulp.task('default', ['build', 'serve', 'watch']);