UNPKG

1.98 kBJavaScriptView Raw
1// replace with the real thing when PR is merged
2// https://github.com/angular/universal/pull/464
3"use strict";
4Object.defineProperty(exports, "__esModule", { value: true });
5class PrerenderWebpackPlugin {
6 constructor(options) {
7 this.options = options;
8 // maintain your platform instance
9 this.bootloader = require(this.options.configPath).getBootloader();
10 }
11 apply(compiler) {
12 compiler.plugin('emit', (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((html) => {
22 compilation.assets[this.options.templatePath] = {
23 source: () => html,
24 size: () => html.length
25 };
26 callback();
27 });
28 }
29 else {
30 callback();
31 }
32 });
33 }
34 decacheAppFiles() {
35 // delete all app files from cache, but keep libs
36 // this is needed so that the config file can reimport up to date
37 // versions of the app files
38 delete require.cache[this.options.configPath];
39 Object.keys(require.cache)
40 .filter(key => key.startsWith(this.options.appPath))
41 .forEach(function (key) {
42 // console.log('===', key);
43 delete require.cache[key];
44 });
45 }
46}
47exports.PrerenderWebpackPlugin = PrerenderWebpackPlugin;
48;
49//# sourceMappingURL=/users/hans/sources/angular-cli/utilities/prerender-webpack-plugin.js.map
\No newline at end of file