source: trip-planner-front/node_modules/@angular-devkit/build-angular/src/utils/index-file/index-html-generator.js

Last change on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 4.6 KB
Line 
1"use strict";
2/**
3 * @license
4 * Copyright Google LLC All Rights Reserved.
5 *
6 * Use of this source code is governed by an MIT-style license that can be
7 * found in the LICENSE file at https://angular.io/license
8 */
9var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10 if (k2 === undefined) k2 = k;
11 Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
12}) : (function(o, m, k, k2) {
13 if (k2 === undefined) k2 = k;
14 o[k2] = m[k];
15}));
16var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17 Object.defineProperty(o, "default", { enumerable: true, value: v });
18}) : function(o, v) {
19 o["default"] = v;
20});
21var __importStar = (this && this.__importStar) || function (mod) {
22 if (mod && mod.__esModule) return mod;
23 var result = {};
24 if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25 __setModuleDefault(result, mod);
26 return result;
27};
28Object.defineProperty(exports, "__esModule", { value: true });
29exports.IndexHtmlGenerator = void 0;
30const fs = __importStar(require("fs"));
31const path_1 = require("path");
32const strip_bom_1 = require("../strip-bom");
33const augment_index_html_1 = require("./augment-index-html");
34const inline_critical_css_1 = require("./inline-critical-css");
35const inline_fonts_1 = require("./inline-fonts");
36class IndexHtmlGenerator {
37 constructor(options) {
38 var _a, _b;
39 this.options = options;
40 const extraPlugins = [];
41 if ((_a = this.options.optimization) === null || _a === void 0 ? void 0 : _a.fonts.inline) {
42 extraPlugins.push(inlineFontsPlugin(this));
43 }
44 if ((_b = this.options.optimization) === null || _b === void 0 ? void 0 : _b.styles.inlineCritical) {
45 extraPlugins.push(inlineCriticalCssPlugin(this));
46 }
47 this.plugins = [augmentIndexHtmlPlugin(this), ...extraPlugins, postTransformPlugin(this)];
48 }
49 async process(options) {
50 let content = strip_bom_1.stripBom(await this.readIndex(this.options.indexPath));
51 const warnings = [];
52 const errors = [];
53 for (const plugin of this.plugins) {
54 const result = await plugin(content, options);
55 if (typeof result === 'string') {
56 content = result;
57 }
58 else {
59 content = result.content;
60 if (result.warnings.length) {
61 warnings.push(...result.warnings);
62 }
63 if (result.errors.length) {
64 errors.push(...result.errors);
65 }
66 }
67 }
68 return {
69 content,
70 warnings,
71 errors,
72 };
73 }
74 async readAsset(path) {
75 return fs.promises.readFile(path, 'utf-8');
76 }
77 async readIndex(path) {
78 return fs.promises.readFile(path, 'utf-8');
79 }
80}
81exports.IndexHtmlGenerator = IndexHtmlGenerator;
82function augmentIndexHtmlPlugin(generator) {
83 const { deployUrl, crossOrigin, sri = false, entrypoints } = generator.options;
84 return async (html, options) => {
85 const { lang, baseHref, outputPath = '', noModuleFiles, files, moduleFiles } = options;
86 return augment_index_html_1.augmentIndexHtml({
87 html,
88 baseHref,
89 deployUrl,
90 crossOrigin,
91 sri,
92 lang,
93 entrypoints,
94 loadOutputFile: (filePath) => generator.readAsset(path_1.join(outputPath, filePath)),
95 noModuleFiles,
96 moduleFiles,
97 files,
98 });
99 };
100}
101function inlineFontsPlugin({ options }) {
102 var _a;
103 const inlineFontsProcessor = new inline_fonts_1.InlineFontsProcessor({
104 minify: (_a = options.optimization) === null || _a === void 0 ? void 0 : _a.styles.minify,
105 WOFFSupportNeeded: options.WOFFSupportNeeded,
106 });
107 return async (html) => inlineFontsProcessor.process(html);
108}
109function inlineCriticalCssPlugin(generator) {
110 var _a;
111 const inlineCriticalCssProcessor = new inline_critical_css_1.InlineCriticalCssProcessor({
112 minify: (_a = generator.options.optimization) === null || _a === void 0 ? void 0 : _a.styles.minify,
113 deployUrl: generator.options.deployUrl,
114 readAsset: (filePath) => generator.readAsset(filePath),
115 });
116 return async (html, options) => inlineCriticalCssProcessor.process(html, { outputPath: options.outputPath });
117}
118function postTransformPlugin({ options }) {
119 return async (html) => (options.postTransform ? options.postTransform(html) : html);
120}
Note: See TracBrowser for help on using the repository browser.