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 path = require("node:path");
|
14 | const util_1 = require("util");
|
15 | const core_1 = require("@angular-devkit/core");
|
16 | const lodash_1 = require("lodash");
|
17 | const common_1 = require("@angular-builders/common");
|
18 | const webpack_config_merger_1 = require("./webpack-config-merger");
|
19 | exports.defaultWebpackConfigPath = 'webpack.config.js';
|
20 | class CustomWebpackBuilder {
|
21 | static buildWebpackConfig(root, config, baseWebpackConfig, buildOptions, targetOptions, logger) {
|
22 | return __awaiter(this, void 0, void 0, function* () {
|
23 | if (!config) {
|
24 | return baseWebpackConfig;
|
25 | }
|
26 | const normalizedRootPath = (0, core_1.getSystemPath)(root);
|
27 | const tsConfig = path.join(normalizedRootPath, buildOptions.tsConfig);
|
28 | const webpackConfigPath = path.join(normalizedRootPath, config.path || exports.defaultWebpackConfigPath);
|
29 | const configOrFactoryOrPromise = yield (0, common_1.loadModule)(webpackConfigPath, tsConfig, logger);
|
30 | if (typeof configOrFactoryOrPromise === 'function') {
|
31 |
|
32 |
|
33 | const finalWebpackConfig = yield configOrFactoryOrPromise(baseWebpackConfig, buildOptions, targetOptions);
|
34 | logConfigProperties(config, finalWebpackConfig, logger);
|
35 | return finalWebpackConfig;
|
36 | }
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 | const resolvedConfig = yield configOrFactoryOrPromise;
|
44 | const finalWebpackConfig = (0, webpack_config_merger_1.mergeConfigs)(baseWebpackConfig, resolvedConfig, config.mergeRules, config.replaceDuplicatePlugins);
|
45 | logConfigProperties(config, finalWebpackConfig, logger);
|
46 | return finalWebpackConfig;
|
47 | });
|
48 | }
|
49 | }
|
50 | exports.CustomWebpackBuilder = CustomWebpackBuilder;
|
51 | function logConfigProperties(config, webpackConfig, logger) {
|
52 | var _a;
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | if ((_a = config.verbose) === null || _a === void 0 ? void 0 : _a.properties) {
|
58 | for (const property of config.verbose.properties) {
|
59 | const value = (0, lodash_1.get)(webpackConfig, property);
|
60 | if (value) {
|
61 | const message = (0, util_1.inspect)(value, false, config.verbose.serializationDepth);
|
62 | logger.info(message);
|
63 | }
|
64 | }
|
65 | }
|
66 | }
|
67 |
|
\ | No newline at end of file |