forked from GoogleChromeLabs/airhorn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
145 lines (131 loc) · 3.21 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
135
136
137
138
139
140
141
142
143
144
import gulp from 'gulp';
import del from 'del';
import gulpLoadPlugins from 'gulp-load-plugins';
import {
rollup
} from 'rollup';
import {
terser
} from 'rollup-plugin-terser';
import babel from 'rollup-plugin-babel';
const $ = gulpLoadPlugins();
// Optimize images
const images = () =>
gulp.src('app/images/**/*')
.pipe($.cache($.imagemin({
progressive: true,
interlaced: true
})))
.pipe(gulp.dest('dist/images'))
.pipe($.size({
title: 'images'
}));
const sounds = () =>
gulp.src('app/sounds/**/*')
.pipe(gulp.dest('dist/sounds'))
.pipe($.size({
title: 'sounds'
}));
const wellknown = () =>
gulp.src('app/.well-known/**/*')
.pipe(gulp.dest('dist/.well-known'))
.pipe($.size({
title: 'wellknown'
}));
const scripts = () =>
gulp.src('app/scripts/**/*')
.pipe(gulp.dest('dist/scripts'))
.pipe($.size({
title: 'scripts'
}));
// Copy all files at the root level (app)
const copy = () =>
gulp.src(['app/*', '!app/*.html'], {
dot: true
}).pipe(gulp.dest('dist'))
.pipe($.size({
title: 'copy'
}));
// Compile and automatically prefix stylesheets
const styles = () => {
const AUTOPREFIXER_BROWSERS = [
'ie >= 10',
'ie_mob >= 10',
'ff >= 30',
'chrome >= 34',
'safari >= 7',
'opera >= 23',
'ios >= 7',
'android >= 4.4',
'bb >= 10'
];
// For best performance, don't add Sass partials to `gulp.src`
return gulp.src([
'app/styles/**/*.css'
])
.pipe($.autoprefixer(AUTOPREFIXER_BROWSERS))
.pipe(gulp.dest('.tmp/styles'))
.pipe($.concat('main.css'))
.pipe($.cssnano())
.pipe($.size({
title: 'styles'
}))
.pipe(gulp.dest('dist/styles'));
};
// Scan your HTML for assets & optimize them
const html = () => {
return gulp.src('app/**/*.html')
.pipe($.useref({
searchPath: '{.tmp,app}',
noAssets: true
}))
.pipe($.if('*.html', $.htmlmin({
removeComments: true,
collapseWhitespace: true,
collapseBooleanAttributes: true,
removeAttributeQuotes: true,
removeRedundantAttributes: true,
removeEmptyAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
removeOptionalTags: true
})))
// Output files
.pipe($.if('*.html', $.size({
title: 'html',
showFiles: true
})))
.pipe(gulp.dest('dist'));
};
const clean = (done) => {
return del(['.tmp', 'dist/*', '!dist/.git'], {
dot: true
}, done);
};
const client = (done) => {
return rollup({
input: './app/scripts/main.min.js',
plugins: [
babel({
babelrc: false,
presets: [
['@babel/env', {
'targets': {
'chrome': '41'
}
}]
],
exclude: 'node_modules/**'
}),
terser()
]
}).then(bundle => {
return bundle.write({
file: './dist/scripts/main.min.js',
format: 'iife'
});
});
};
const build = gulp.series(clean, copy, scripts, gulp.parallel(client, styles, sounds, wellknown, html, images));
gulp.task('default', build);
gulp.task('clean', clean);