@nx/vite
Version:
54 lines (53 loc) • 2.53 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.servePostTargetTransformer = servePostTargetTransformer;
const utils_1 = require("./utils");
function servePostTargetTransformer(migrationLogs) {
return (target, tree, projectDetails, inferredTargetConfiguration) => {
const viteConfigPath = (0, utils_1.getViteConfigPath)(tree, projectDetails.root);
if (target.options) {
removePropertiesFromTargetOptions(tree, target.options, viteConfigPath, projectDetails.root, projectDetails.projectName, migrationLogs, true);
}
if (target.configurations) {
for (const configurationName in target.configurations) {
const configuration = target.configurations[configurationName];
removePropertiesFromTargetOptions(tree, configuration, viteConfigPath, projectDetails.root, projectDetails.projectName, migrationLogs);
}
if (Object.keys(target.configurations).length === 0) {
if ('defaultConfiguration' in target) {
delete target.defaultConfiguration;
}
delete target.configurations;
}
if ('defaultConfiguration' in target &&
!target.configurations[target.defaultConfiguration]) {
delete target.defaultConfiguration;
}
}
return target;
};
}
function removePropertiesFromTargetOptions(tree, targetOptions, viteConfigPath, projectRoot, projectName, migrationLogs, defaultOptions = false) {
if ('buildTarget' in targetOptions) {
delete targetOptions.buildTarget;
}
if ('buildLibsFromSource' in targetOptions) {
migrationLogs.addLog({
executorName: '@nx/vite:dev-server',
project: projectName,
log: `Encountered 'buildLibsFromSource' in project.json. This property will be added to your Vite config file via the '@nx/vite:build' executor migration.`,
});
delete targetOptions.buildLibsFromSource;
}
if ('hmr' in targetOptions) {
delete targetOptions.hmr;
}
if ('proxyConfig' in targetOptions) {
migrationLogs.addLog({
executorName: '@nx/vite:dev-server',
project: projectName,
log: `Encountered 'proxyConfig' in project.json. You will need to copy the contents of this file to the 'server.proxy' property in your Vite config file.`,
});
delete targetOptions.proxyConfig;
}
}