@nx/webpack
Version:
58 lines (51 loc) • 1.95 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = update;
const devkit_1 = require("@nx/devkit");
const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
async function update(tree) {
const unmigratedConfigs = [];
const migrate = (options) => {
if (!options.proxyConfig)
return;
if (options.proxyConfig.endsWith('.json')) {
(0, devkit_1.updateJson)(tree, options.proxyConfig, (json) => {
if (Array.isArray(json))
return json;
if (typeof json === 'object') {
return Object.keys(json).map((context) => ({
context: [context],
...json[context],
}));
}
return json;
});
}
else {
// For non-JSON files, it's not possible to automatically update the proxy config
// since its content can vary greatly.
unmigratedConfigs.push(options.proxyConfig);
}
};
(0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/webpack:dev-server', migrate);
// React dev-server calls Webpack dev-server.
(0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/react:module-federation-dev-server', migrate);
if (unmigratedConfigs.length > 0) {
devkit_1.logger.warn(`Some proxy config files need to be updated manually.
${unmigratedConfigs.join('\n ')}
Webpack-dev-server v5 changed the proxy config schema to accept only an array.
For example, if you had the following:
"proxy": {
"/api": {
"target": "http://localhost:3000"
}
}
It needs to be updated to:
"proxy": [{
"context": ["/api"],
"target": "http://localhost:3000"
}]
More information: https://github.com/webpack/webpack-dev-server/blob/master/migration-v5.md
`);
}
}
;