1 |
|
2 |
|
3 | "use strict";
|
4 | Object.defineProperty(exports, "__esModule", { value: true });
|
5 | class PrerenderWebpackPlugin {
|
6 | constructor(options) {
|
7 | this.options = options;
|
8 |
|
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 |
|
15 |
|
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 |
|
36 |
|
37 |
|
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 |
|
43 | delete require.cache[key];
|
44 | });
|
45 | }
|
46 | }
|
47 | exports.PrerenderWebpackPlugin = PrerenderWebpackPlugin;
|
48 | ;
|
49 |
|
\ | No newline at end of file |