diff --git a/packages/vite/src/utils/generator-utils.ts b/packages/vite/src/utils/generator-utils.ts index c8e4a4bc8041d..1d4f35623e603 100644 --- a/packages/vite/src/utils/generator-utils.ts +++ b/packages/vite/src/utils/generator-utils.ts @@ -372,12 +372,15 @@ export function moveAndEditIndexHtml( let indexHtmlPath = projectConfig.targets[buildTarget].options?.index ?? `${projectConfig.root}/src/index.html`; - const mainPath = ( + let mainPath = projectConfig.targets[buildTarget].options?.main ?? `${projectConfig.root}/src/main.ts${ options.uiFramework === 'react' ? 'x' : '' - }` - ).replace(projectConfig.root, ''); + }`; + + if (projectConfig.root !== '.') { + mainPath = mainPath.replace(projectConfig.root, ''); + } if ( !tree.exists(indexHtmlPath) &&