-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
74 lines (63 loc) · 2.72 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
69
70
71
72
73
74
'use strict';
const path = require('path');
const gulp = require('gulp');
const mergeStgream = require('merge-stream');
const del = require('del');
const polymerJsonPath = path.join(process.cwd(), 'polymer.json');
const polymerJSON = require(polymerJsonPath);
const polymer = require('polymer-build');
const polymerProject = new polymer.PolymerProject(polymerJSON);
const buildDirectory = 'build/bundled';
/**
* Waits for the given ReadableStream
*/
function waitFor(stream) {
return new Promise((resolve, reject) => {
stream.on('end', resolve);
stream.on('error', reject);
});
}
function build() {
return new Promise((resolve, reject) => {
// OK, so firts, thing we do is clear the build
console.log('Deleting build/ directory...');
del([buildDirectory])
.then(_ => {
// OK, now lets get you files
let sourceStream = polymerProject.sources()
// oh, well do you want to minify stuff? Go for it!
// Here's how splitHtml & gulpif work
.pipe(polymerProject.splitHtml())
// .pipe(gulpif(/\.js$/, uglify()))
// .pipe(gulpif(/\.css$/, cssSlam()))
// .pipe(gulpif(/\.html$/, htmlMinifier()))
.pipe(polymerProject.rejoinHtml());
// OK, now lets do the same to your dependencies
let depsStream = polymerProject.dependencies()
.pipe(polymerProject.splitHtml())
// .pipe(gulpif(/\.js$/, uglify()))
// .pipe(gulpif(/\.css$/, cssSlam()))
// .pipe(gulpif(/\.html$/, htmlMinifier()))
.pipe(polymerProject.rejoinHtml());
// OK, now lets merge them into a single build stream.
let buildStream = mergeStream(sourcesStream, depsStream)
.once('data', () => {
console.log('Analyzing build dependenties...');
});
// If you want bundling, do dome bundling
buildStream = buildStream.pipe(polymerProject.bundler);
// If you want to add prefetch links, do it!
buildStream = buildStream.pipe(new PrefetchTransform(polymerProject));
// OK, time to pipe to the build directory
buildStream = buildStream.pipe(gulp.dest(buildDirectory));
// waitFot the buildStream to complete
return waitFor(buildStream);
})
.then(_ => {
// You di it!
console.log('Build complete!');
resolve();
});
});
}
gulp.task('default', build);