UNPKG

@nx/vite

Version:

The Nx Plugin for building and testing applications using Vite

64 lines (63 loc) 2.84 kB
"use strict"; Object.defineProperty(exports, "convertNonVite", { enumerable: true, get: function() { return convertNonVite; } }); const _devkit = require("@nx/devkit"); const _findviteconfig = require("../../../utils/find-vite-config"); const _generatorutils = require("../../../utils/generator-utils"); const _tssolutionsetup = require("@nx/js/src/utils/typescript/ts-solution-setup"); async function convertNonVite(tree, schema, projectRoot, _projectType, targets) { // Check if it has vite const hasViteConfig = (0, _findviteconfig.findViteConfig)(tree, projectRoot); const hasIndexHtmlAtRoot = tree.exists((0, _devkit.joinPathFragments)(projectRoot, 'index.html')); // Check if it has webpack const hasWebpackConfig = (0, _findviteconfig.findWebpackConfig)(tree, projectRoot); const projectType = (0, _tssolutionsetup.getProjectType)(tree, projectRoot, _projectType); if (hasWebpackConfig) { if (projectType === 'application') { (0, _generatorutils.moveAndEditIndexHtml)(tree, schema); } (0, _generatorutils.deleteWebpackConfig)(tree, projectRoot, hasWebpackConfig); (0, _generatorutils.editTsConfig)(tree, schema); return; } if (projectType === 'application' && hasViteConfig && hasIndexHtmlAtRoot && !hasWebpackConfig) { throw new Error(`The project ${schema.project} is already configured to use Vite.`); return; } if (projectType === 'library' && hasViteConfig) { // continue anyway - it could need to be updated - only update vite.config.ts in any case (0, _generatorutils.editTsConfig)(tree, schema); return; } // Does the project have js executors? const { supported: jsTargetName, unsupported } = (0, _generatorutils.findExistingJsBuildTargetInProject)(targets); if (jsTargetName) { (0, _generatorutils.editTsConfig)(tree, schema); return; } if (unsupported) { throw new Error(` Nx cannot convert your project to use vite. Please try again with a different project. `); } // If it's a library, it's most possible it's non-buildable // So fix the tsconfig and return, to continue with the rest of the setup if (projectType === 'library' && !hasViteConfig && !hasWebpackConfig && !jsTargetName) { (0, _generatorutils.editTsConfig)(tree, schema); return; } /** * The project is an app. * The project has no js executors, no webpack config, no vite config. * We did not find any configuration that hints the project can * definitely be converted. * So, we should warn the user about it. * They can choose whether to convert it or not */ await (0, _generatorutils.handleUnknownConfiguration)(schema.project); } //# sourceMappingURL=convert-non-vite.js.map