-
Notifications
You must be signed in to change notification settings - Fork 482
/
index.js
36 lines (29 loc) · 1.01 KB
/
index.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
var universal = require('angular2-universal-preview');
var through = require('through2');
var gutil = require('gutil');
var PluginError = gutil.PluginError;
module.exports = function gulpAngular2Render(config) {
return through.obj(function transform(file, enc, cb) {
if (file.isStream()) {
return cb(new PluginError('angular2-gulp-prerender', 'Streaming is not supported'));
}
var str = file.contents.toString();
var renderPromise = universal.renderToString;
var args = [config.App, config.providers];
if (config.preboot) {
renderPromise = universal.renderToStringWithPreboot;
args.push(config.preboot);
}
renderPromise.apply(null, args)
.then(function(serializedApp) {
var html = str.replace(
// <selector></selector>
universal.selectorRegExpFactory(universal.selectorResolver(config.App)),
// <selector>{{ serializedCmp }}</selector>
serializedApp
);
file.contents = new Buffer(html);
cb(null, file)
});
});
}