piral-cli-webpack5
Version:
Provides debug and build capabilities for pilets and Piral instances using Webpack v5.
44 lines • 1.76 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.extendConfig = extendConfig;
const fs_1 = require("fs");
async function extendConfig([webPackConfig, enhancer], otherConfigPath, overrides = {}) {
const original = webPackConfig;
if ((0, fs_1.existsSync)(otherConfigPath)) {
try {
let otherConfig = require(otherConfigPath);
if (otherConfig.default) {
// The webpack config file appears to be an ESM module;
// this interop should give us the actual exported config
otherConfig = otherConfig.default;
}
if (typeof otherConfig === 'function') {
// support Promise for returned config:
// https://webpack.js.org/configuration/configuration-types/#exporting-a-promise
webPackConfig = await otherConfig(webPackConfig);
}
else if (typeof otherConfig === 'object') {
webPackConfig = {
...webPackConfig,
...otherConfig,
};
}
else {
console.warn(`Did not recognize the export from "${otherConfigPath}". Skipping.`);
}
}
catch (ex) {
console.error(`Error while using the config from "${otherConfigPath}": ${ex}`);
}
}
['entry', 'output', 'optimization'].forEach((s) => {
if (original[s] !== webPackConfig[s]) {
console.warn(`You've overwritten the "${s}" section of the Webpack config. Make sure you know what you are doing.`);
}
});
return enhancer({
...webPackConfig,
...overrides,
});
}
//# sourceMappingURL=helpers.js.map