This repository has been archived by the owner on Mar 9, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
68 lines (59 loc) · 1.84 KB
/
gulpfile.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
const gulp = require('gulp');
const babel = require('gulp-babel');
const cssSlam = require('css-slam').gulp;
const del = require('del');
const gulpif = require('gulp-if');
const htmlMinifier = require('gulp-htmlmin');
const HtmlSplitter = require('polymer-build').HtmlSplitter;
const mergeStreams = require('merge-stream');
const PolymerProject = require('polymer-build').PolymerProject;
const uglify = require('gulp-uglify');
const workbox = require('workbox-build');
gulp.task('default', ['build'], () => {
// Generate Service Worker (from /sw.js)
workbox.injectManifest({
globDirectory: 'build/default/',
globPatterns: [
'**/*'
],
swDest: 'build/default/sw.js',
swSrc: 'sw.js'
});
});
gulp.task('build', ['clean'], () => {
const project = new PolymerProject(require('./polymer.json'));
const sourcesHtmlSplitter = new HtmlSplitter();
// Combine sources and dependencies
const stream = mergeStreams(project.sources(), project.dependencies());
// Transform code
stream
.pipe(sourcesHtmlSplitter.split())
.pipe(gulpif(/\.css$/, cssSlam({
stripWhitespace: true
})))
.pipe(gulpif(/\.html$/, cssSlam({
stripWhitespace: true
})))
.pipe(gulpif(/\.html$/, htmlMinifier({
collapseWhitespace: true,
removeComments: true
})))
.pipe(gulpif(/\.js$/, babel({ presets: ['es2015'] })))
.pipe(gulpif(/\.js$/, uglify()))
.pipe(sourcesHtmlSplitter.rejoin())
.pipe(project.addCustomElementsEs5Adapter())
.pipe(gulp.dest('build/default/'))
;
// Copy Web Components polyfills
gulp.src('bower_components/webcomponentsjs/*ents*.js')
.pipe(gulp.dest('build/default/bower_components/webcomponentsjs/'));
// Copy Workbox files
gulp.src('workbox-sw*')
.pipe(gulp.dest('build/default/'));
return stream;
});
gulp.task('clean', () => {
return del([
'build/'
]);
});