UNPKG

3.99 kBJavaScriptView Raw
1"use strict";
2var __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};
11Object.defineProperty(exports, "__esModule", { value: true });
12exports.CustomWebpackBuilder = exports.defaultWebpackConfigPath = void 0;
13const path = require("node:path");
14const util_1 = require("util");
15const core_1 = require("@angular-devkit/core");
16const lodash_1 = require("lodash");
17const common_1 = require("@angular-builders/common");
18const webpack_config_merger_1 = require("./webpack-config-merger");
19exports.defaultWebpackConfigPath = 'webpack.config.js';
20class 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 // The exported function can return a new configuration synchronously
32 // or return a promise that resolves to a new configuration.
33 const finalWebpackConfig = yield configOrFactoryOrPromise(baseWebpackConfig, buildOptions, targetOptions);
34 logConfigProperties(config, finalWebpackConfig, logger);
35 return finalWebpackConfig;
36 }
37 // The user can also export a promise that resolves to a `Configuration` object.
38 // Suppose the following example:
39 // `module.exports = new Promise(resolve => resolve({ ... }))`
40 // This is valid both for promise and non-promise cases. If users export
41 // a plain object, for instance, `module.exports = { ... }`, then it will
42 // be wrapped into a promise and also `awaited`.
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}
50exports.CustomWebpackBuilder = CustomWebpackBuilder;
51function logConfigProperties(config, webpackConfig, logger) {
52 var _a;
53 // There's no reason to log the entire configuration object
54 // since Angular's Webpack configuration is huge by default
55 // and doesn't bring any meaningful context by being printed
56 // entirely. Users can provide a list of properties they want to be logged.
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, /* showHidden */ false, config.verbose.serializationDepth);
62 logger.info(message);
63 }
64 }
65 }
66}
67//# sourceMappingURL=custom-webpack-builder.js.map
\No newline at end of file