1 | "use strict";
|
2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4 | return new (P || (P = Promise))(function (resolve, reject) {
|
5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9 | });
|
10 | };
|
11 | Object.defineProperty(exports, "__esModule", { value: true });
|
12 | exports.CustomWebpackBuilder = exports.defaultWebpackConfigPath = void 0;
|
13 | const util_1 = require("util");
|
14 | const core_1 = require("@angular-devkit/core");
|
15 | const lodash_1 = require("lodash");
|
16 | const utils_1 = require("./utils");
|
17 | const webpack_config_merger_1 = require("./webpack-config-merger");
|
18 | exports.defaultWebpackConfigPath = 'webpack.config.js';
|
19 | class CustomWebpackBuilder {
|
20 | static buildWebpackConfig(root, config, baseWebpackConfig, buildOptions, targetOptions, logger) {
|
21 | return __awaiter(this, void 0, void 0, function* () {
|
22 | if (!config) {
|
23 | return baseWebpackConfig;
|
24 | }
|
25 | const webpackConfigPath = config.path || exports.defaultWebpackConfigPath;
|
26 | const path = `${(0, core_1.getSystemPath)(root)}/${webpackConfigPath}`;
|
27 | const tsConfig = `${(0, core_1.getSystemPath)(root)}/${buildOptions.tsConfig}`;
|
28 | const configOrFactoryOrPromise = yield resolveCustomWebpackConfig(path, tsConfig, logger);
|
29 | if (typeof configOrFactoryOrPromise === 'function') {
|
30 |
|
31 |
|
32 | const finalWebpackConfig = yield configOrFactoryOrPromise(baseWebpackConfig, buildOptions, targetOptions);
|
33 | logConfigProperties(config, finalWebpackConfig, logger);
|
34 | return finalWebpackConfig;
|
35 | }
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | const resolvedConfig = yield configOrFactoryOrPromise;
|
43 | const finalWebpackConfig = (0, webpack_config_merger_1.mergeConfigs)(baseWebpackConfig, resolvedConfig, config.mergeRules, config.replaceDuplicatePlugins);
|
44 | logConfigProperties(config, finalWebpackConfig, logger);
|
45 | return finalWebpackConfig;
|
46 | });
|
47 | }
|
48 | }
|
49 | exports.CustomWebpackBuilder = CustomWebpackBuilder;
|
50 | function resolveCustomWebpackConfig(path, tsConfig, logger) {
|
51 | return __awaiter(this, void 0, void 0, function* () {
|
52 | (0, utils_1.tsNodeRegister)(path, tsConfig, logger);
|
53 | return (0, utils_1.loadModule)(path);
|
54 | });
|
55 | }
|
56 | function logConfigProperties(config, webpackConfig, logger) {
|
57 | var _a;
|
58 |
|
59 |
|
60 |
|
61 |
|
62 | if ((_a = config.verbose) === null || _a === void 0 ? void 0 : _a.properties) {
|
63 | for (const property of config.verbose.properties) {
|
64 | const value = (0, lodash_1.get)(webpackConfig, property);
|
65 | if (value) {
|
66 | const message = (0, util_1.inspect)(value, false, config.verbose.serializationDepth);
|
67 | logger.info(message);
|
68 | }
|
69 | }
|
70 | }
|
71 | }
|
72 |
|
\ | No newline at end of file |