UNPKG

2.23 kBJavaScriptView Raw
1// replace with the real thing when PR is merged
2// https://github.com/angular/universal/pull/464
3"use strict";
4var PrerenderWebpackPlugin = (function () {
5 function PrerenderWebpackPlugin(options) {
6 this.options = options;
7 // maintain your platform instance
8 this.bootloader = require(this.options.configPath).getBootloader();
9 }
10 PrerenderWebpackPlugin.prototype.apply = function (compiler) {
11 var _this = this;
12 compiler.plugin('emit', function (compilation, callback) {
13 if (compilation.assets.hasOwnProperty(_this.options.templatePath)) {
14 // we need to cache the template file to be able to re-serialize it
15 // even when it is not being emitted
16 _this.cachedTemplate = compilation.assets[_this.options.templatePath].source();
17 }
18 if (_this.cachedTemplate) {
19 _this.decacheAppFiles();
20 require(_this.options.configPath).serialize(_this.bootloader, _this.cachedTemplate)
21 .then(function (html) {
22 compilation.assets[_this.options.templatePath] = {
23 source: function () { return html; },
24 size: function () { return html.length; }
25 };
26 callback();
27 });
28 }
29 else {
30 callback();
31 }
32 });
33 };
34 PrerenderWebpackPlugin.prototype.decacheAppFiles = function () {
35 var _this = this;
36 // delete all app files from cache, but keep libs
37 // this is needed so that the config file can reimport up to date
38 // versions of the app files
39 delete require.cache[this.options.configPath];
40 Object.keys(require.cache)
41 .filter(function (key) { return key.startsWith(_this.options.appPath); })
42 .forEach(function (key) {
43 // console.log('===', key);
44 delete require.cache[key];
45 });
46 };
47 return PrerenderWebpackPlugin;
48}());
49exports.PrerenderWebpackPlugin = PrerenderWebpackPlugin;
50;
51//# sourceMappingURL=/Users/hansl/Sources/angular-cli/packages/angular-cli/utilities/prerender-webpack-plugin.js.map
\No newline at end of file