UNPKG

@msfw/cli

Version:

Install the package in your project directory with:

43 lines (42 loc) 1.73 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.mergeWebpackConfig = mergeWebpackConfig; const webpack_merge_1 = __importDefault(require("webpack-merge")); const logger_1 = require("../../logger"); const utils_1 = require("../../utils"); function addAlias(webpackConfig, webpackAlias) { if (webpackConfig.resolve) { // TODO: ensure is a plain object, if not, log an error. webpackConfig.resolve.alias = Object.assign(webpackConfig.resolve.alias || {}, webpackAlias); } (0, logger_1.log)('Added webpack alias.'); } function giveTotalControl(webpackConfig, configureWebpack, context) { if ((0, utils_1.isFunction)(configureWebpack)) { webpackConfig = configureWebpack(webpackConfig, context); if (!webpackConfig) { throw new Error("craco: 'webpack.configure' function didn't returned a webpack config object."); } } else { webpackConfig = (0, webpack_merge_1.default)(webpackConfig, configureWebpack); } (0, logger_1.log)("Merged webpack config with 'webpack.configure'."); return webpackConfig; } function mergeWebpackConfig(msfwConfig, webpackConfig, context) { let resultingWebpackConfig = webpackConfig; if (msfwConfig.webpack) { const { alias, configure } = msfwConfig.webpack; if (alias) { addAlias(resultingWebpackConfig, alias); } if (configure) { resultingWebpackConfig = giveTotalControl(resultingWebpackConfig, configure, context); } } return resultingWebpackConfig; }