source: trip-planner-front/node_modules/@angular-devkit/build-angular/src/utils/webpack-browser-config.js@ 571e0df

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

initial commit

  • Property mode set to 100644
File size: 6.9 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.getIndexInputFile = exports.getIndexOutputFile = exports.generateBrowserWebpackConfigFromContext = exports.generateI18nBrowserWebpackConfigFromContext = exports.generateWebpackConfig = void 0;
30const core_1 = require("@angular-devkit/core");
31const path = __importStar(require("path"));
32const webpack_1 = require("webpack");
33const webpack_merge_1 = require("webpack-merge");
34const utils_1 = require("../utils");
35const read_tsconfig_1 = require("../utils/read-tsconfig");
36const builder_watch_plugin_1 = require("../webpack/plugins/builder-watch-plugin");
37const i18n_options_1 = require("./i18n-options");
38async function generateWebpackConfig(workspaceRoot, projectRoot, sourceRoot, options, webpackPartialGenerator, logger, extraBuildOptions) {
39 // Ensure Build Optimizer is only used with AOT.
40 if (options.buildOptimizer && !options.aot) {
41 throw new Error(`The 'buildOptimizer' option cannot be used without 'aot'.`);
42 }
43 const tsConfigPath = path.resolve(workspaceRoot, options.tsConfig);
44 const tsConfig = read_tsconfig_1.readTsconfig(tsConfigPath);
45 const ts = await Promise.resolve().then(() => __importStar(require('typescript')));
46 const scriptTarget = tsConfig.options.target || ts.ScriptTarget.ES5;
47 const buildOptions = { ...options, ...extraBuildOptions };
48 const wco = {
49 root: workspaceRoot,
50 logger: logger.createChild('webpackConfigOptions'),
51 projectRoot,
52 sourceRoot,
53 buildOptions,
54 tsConfig,
55 tsConfigPath,
56 scriptTarget,
57 };
58 wco.buildOptions.progress = utils_1.defaultProgress(wco.buildOptions.progress);
59 const webpackConfig = webpack_merge_1.merge(webpackPartialGenerator(wco));
60 return webpackConfig;
61}
62exports.generateWebpackConfig = generateWebpackConfig;
63async function generateI18nBrowserWebpackConfigFromContext(options, context, webpackPartialGenerator, extraBuildOptions = {}) {
64 var _a;
65 const { buildOptions, i18n } = await i18n_options_1.configureI18nBuild(context, options);
66 const result = await generateBrowserWebpackConfigFromContext(buildOptions, context, webpackPartialGenerator, extraBuildOptions);
67 const config = result.config;
68 if (i18n.shouldInline) {
69 // Remove localize "polyfill" if in AOT mode
70 if (buildOptions.aot) {
71 if (!config.resolve) {
72 config.resolve = {};
73 }
74 if (Array.isArray(config.resolve.alias)) {
75 config.resolve.alias.push({
76 alias: '@angular/localize/init',
77 name: require.resolve('./empty.js'),
78 });
79 }
80 else {
81 if (!config.resolve.alias) {
82 config.resolve.alias = {};
83 }
84 config.resolve.alias['@angular/localize/init'] = require.resolve('./empty.js');
85 }
86 }
87 // Update file hashes to include translation file content
88 const i18nHash = Object.values(i18n.locales).reduce((data, locale) => data + locale.files.map((file) => file.integrity || '').join('|'), '');
89 (_a = config.plugins) !== null && _a !== void 0 ? _a : (config.plugins = []);
90 config.plugins.push({
91 apply(compiler) {
92 compiler.hooks.compilation.tap('build-angular', (compilation) => {
93 webpack_1.javascript.JavascriptModulesPlugin.getCompilationHooks(compilation).chunkHash.tap('build-angular', (_, hash) => {
94 hash.update('$localize' + i18nHash);
95 });
96 });
97 },
98 });
99 }
100 return { ...result, i18n };
101}
102exports.generateI18nBrowserWebpackConfigFromContext = generateI18nBrowserWebpackConfigFromContext;
103async function generateBrowserWebpackConfigFromContext(options, context, webpackPartialGenerator, extraBuildOptions = {}) {
104 const projectName = context.target && context.target.project;
105 if (!projectName) {
106 throw new Error('The builder requires a target.');
107 }
108 const workspaceRoot = core_1.normalize(context.workspaceRoot);
109 const projectMetadata = await context.getProjectMetadata(projectName);
110 const projectRoot = core_1.resolve(workspaceRoot, core_1.normalize(projectMetadata.root || ''));
111 const projectSourceRoot = projectMetadata.sourceRoot;
112 const sourceRoot = projectSourceRoot
113 ? core_1.resolve(workspaceRoot, core_1.normalize(projectSourceRoot))
114 : undefined;
115 const normalizedOptions = utils_1.normalizeBrowserSchema(workspaceRoot, projectRoot, sourceRoot, options);
116 const config = await generateWebpackConfig(core_1.getSystemPath(workspaceRoot), core_1.getSystemPath(projectRoot), sourceRoot && core_1.getSystemPath(sourceRoot), normalizedOptions, webpackPartialGenerator, context.logger, extraBuildOptions);
117 // If builder watch support is present in the context, add watch plugin
118 // This is internal only and currently only used for testing
119 const watcherFactory = context.watcherFactory;
120 if (watcherFactory) {
121 if (!config.plugins) {
122 config.plugins = [];
123 }
124 config.plugins.push(new builder_watch_plugin_1.BuilderWatchPlugin(watcherFactory));
125 }
126 return {
127 config,
128 projectRoot: core_1.getSystemPath(projectRoot),
129 projectSourceRoot: sourceRoot && core_1.getSystemPath(sourceRoot),
130 };
131}
132exports.generateBrowserWebpackConfigFromContext = generateBrowserWebpackConfigFromContext;
133function getIndexOutputFile(index) {
134 if (typeof index === 'string') {
135 return path.basename(index);
136 }
137 else {
138 return index.output || 'index.html';
139 }
140}
141exports.getIndexOutputFile = getIndexOutputFile;
142function getIndexInputFile(index) {
143 if (typeof index === 'string') {
144 return index;
145 }
146 else {
147 return index.input;
148 }
149}
150exports.getIndexInputFile = getIndexInputFile;
Note: See TracBrowser for help on using the repository browser.