forked from jukbot/smart-industry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
78 lines (68 loc) · 2.67 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
75
76
77
78
'use strict';
// Documentation on what goes into PolymerProject.
const path = require('path');
const gulp = require('gulp');
const gulpif = require('gulp-if');
const uglify = require('gulp-uglify');
const cssSlam = require('css-slam').gulp;
const htmlMinifier = require('gulp-html-minifier');
const mergeStream = require('merge-stream');
const del = require('del');
const PolymerProject = require('polymer-build').PolymerProject;
const HtmlSplitter = require('polymer-build').HtmlSplitter;
const project = new PolymerProject(require('./polymer.json'));
const buildDirectory = 'build/default';
/**
* 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) => {
// Okay, so first thing we do is clear the build
console.log(`Deleting build/ directory...`);
del([buildDirectory])
.then(_ => {
// Okay, now lets get your source files
let sourcesHtmlSplitter = new HtmlSplitter();
let sourcesStream = project.sources()
// Oh, well do you want to minify stuff? Go for it!
// Here's how splitHtml & gulpif work
.pipe(sourcesHtmlSplitter.split())
//.pipe(gulpif(/\.js$/, uglify()))
//.pipe(gulpif(/\.css$/, cssSlam()))
//.pipe(gulpif(/\.html$/, htmlMinifier()))
.pipe(sourcesHtmlSplitter.rejoin());
// Okay now lets do the same to your dependencies
let depsStream = project.dependencies()
//.pipe(sourcesHtmlSplitter .splitHtml())
// .pipe(gulpif(/\.js$/, uglify()))
// .pipe(gulpif(/\.css$/, cssSlam()))
// .pipe(gulpif(/\.html$/, htmlMinifier()))
//.pipe(sourcesHtmlSplitter .rejoinHtml());
// Okay, now lets merge them into a single build stream.
let buildStream = mergeStream(sourcesStream, depsStream)
.once('data', () => {
console.log('Analyzing build dependencies...');
});
// If you want bundling, do some bundling! Explain why?
// buildStream = buildStream.pipe(polymerProject.bundler);
// If you want to add prefetch links, do it! Explain why?
// buildStream = buildStream.pipe(new PrefetchTransform(polymerProject));
// Okay, time to pipe to the build directory
buildStream = buildStream.pipe(gulp.dest(buildDirectory));
// waitFor the buildStream to complete
return waitFor(buildStream);
})
.then(_ => {
// You did it!
console.log('Build complete!');
resolve();
});
});
}
gulp.task('default', build);