diff --git a/e2e/vite/src/vite.test.ts b/e2e/vite/src/vite.test.ts
index f66e51e5ae08e..f1832e42cd541 100644
--- a/e2e/vite/src/vite.test.ts
+++ b/e2e/vite/src/vite.test.ts
@@ -210,7 +210,8 @@ describe('Vite Plugin', () => {
it('should collect coverage', () => {
runCLI(`generate @nrwl/react:lib ${lib} --unitTestRunner=vitest`);
updateFile(`libs/${lib}/vite.config.ts`, () => {
- return `import { defineConfig } from 'vite';
+ return `///
+ import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import viteTsConfigPaths from 'vite-tsconfig-paths';
diff --git a/packages/vite/src/generators/configuration/__snapshots__/configuration.spec.ts.snap b/packages/vite/src/generators/configuration/__snapshots__/configuration.spec.ts.snap
index 8ed5f7076eec2..c6f479f6af860 100644
--- a/packages/vite/src/generators/configuration/__snapshots__/configuration.spec.ts.snap
+++ b/packages/vite/src/generators/configuration/__snapshots__/configuration.spec.ts.snap
@@ -2,6 +2,7 @@
exports[`@nrwl/vite:configuration library mode should add config for building library 1`] = `
"
+ ///
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import viteTsConfigPaths from 'vite-tsconfig-paths';
@@ -58,6 +59,7 @@ import { join } from 'path';
exports[`@nrwl/vite:configuration library mode should set up non buildable library correctly 1`] = `
"
+ ///
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import viteTsConfigPaths from 'vite-tsconfig-paths';
@@ -373,6 +375,7 @@ exports[`@nrwl/vite:configuration transform React app to use Vite by providing c
exports[`@nrwl/vite:configuration transform React app to use Vite should create vite.config file at the root of the app 1`] = `
"
+ ///
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import viteTsConfigPaths from 'vite-tsconfig-paths';
@@ -536,6 +539,7 @@ exports[`@nrwl/vite:configuration transform React app to use Vite should transfo
exports[`@nrwl/vite:configuration transform Web app to use Vite should create vite.config file at the root of the app 1`] = `
"
+ ///
import { defineConfig } from 'vite';
import viteTsConfigPaths from 'vite-tsconfig-paths';
@@ -688,6 +692,7 @@ exports[`@nrwl/vite:configuration transform Web app to use Vite should transform
exports[`@nrwl/vite:configuration vitest should create a vitest configuration if "includeVitest" is true 1`] = `
"
+ ///
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import viteTsConfigPaths from 'vite-tsconfig-paths';
diff --git a/packages/vite/src/generators/vitest/__snapshots__/vitest.spec.ts.snap b/packages/vite/src/generators/vitest/__snapshots__/vitest.spec.ts.snap
index 5af4ee952bcba..b498c4ef5ecfe 100644
--- a/packages/vite/src/generators/vitest/__snapshots__/vitest.spec.ts.snap
+++ b/packages/vite/src/generators/vitest/__snapshots__/vitest.spec.ts.snap
@@ -2,6 +2,7 @@
exports[`vitest generator insourceTests should add the insourceSource option in the vite config 1`] = `
"
+ ///
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import viteTsConfigPaths from 'vite-tsconfig-paths';
@@ -46,6 +47,7 @@ exports[`vitest generator insourceTests should add the insourceSource option in
exports[`vitest generator vite.config should create correct vite.config.ts file for apps 1`] = `
"
+ ///
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import viteTsConfigPaths from 'vite-tsconfig-paths';
@@ -88,6 +90,7 @@ exports[`vitest generator vite.config should create correct vite.config.ts file
exports[`vitest generator vite.config should create correct vite.config.ts file for non buildable libs 1`] = `
"
+ ///
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import viteTsConfigPaths from 'vite-tsconfig-paths';
diff --git a/packages/vite/src/utils/__snapshots__/vite-config-edit-utils.spec.ts.snap b/packages/vite/src/utils/__snapshots__/vite-config-edit-utils.spec.ts.snap
index d5711c5162078..af488af0c5b0e 100644
--- a/packages/vite/src/utils/__snapshots__/vite-config-edit-utils.spec.ts.snap
+++ b/packages/vite/src/utils/__snapshots__/vite-config-edit-utils.spec.ts.snap
@@ -4,6 +4,7 @@ exports[`ensureBuildOptionsInViteConfig should add build and test options if def
"import dts from 'vite-plugin-dts';
import { join } from 'path';
+ ///
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import viteTsConfigPaths from 'vite-tsconfig-paths';
@@ -203,6 +204,7 @@ import { defineConfig } from 'vite';
exports[`ensureBuildOptionsInViteConfig should add build options if it is using conditional config - do nothing for test 1`] = `
"
+ ///
import { defineConfig } from 'vite';
export default defineConfig(({ command, mode, ssrBuild }) => {
if (command === 'serve') {
@@ -269,6 +271,7 @@ exports[`ensureBuildOptionsInViteConfig should not do anything if cannot underst
exports[`ensureBuildOptionsInViteConfig should not do anything if project has everything setup already 1`] = `
"
+ ///
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import viteTsConfigPaths from 'vite-tsconfig-paths';
diff --git a/packages/vite/src/utils/generator-utils.ts b/packages/vite/src/utils/generator-utils.ts
index 10e66718619cd..21f626f281379 100644
--- a/packages/vite/src/utils/generator-utils.ts
+++ b/packages/vite/src/utils/generator-utils.ts
@@ -567,6 +567,7 @@ export function createOrEditViteConfig(
}
viteConfigContent = `
+ ///
import { defineConfig } from 'vite';
${reactPluginImportLine}
import viteTsConfigPaths from 'vite-tsconfig-paths';
diff --git a/packages/vite/src/utils/test-files/test-vite-configs.ts b/packages/vite/src/utils/test-files/test-vite-configs.ts
index b900420038298..195e248f026dc 100644
--- a/packages/vite/src/utils/test-files/test-vite-configs.ts
+++ b/packages/vite/src/utils/test-files/test-vite-configs.ts
@@ -1,4 +1,5 @@
export const noBuildOptions = `
+ ///
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import viteTsConfigPaths from 'vite-tsconfig-paths';
@@ -24,6 +25,7 @@ export const noBuildOptions = `
`;
export const someBuildOptions = `
+ ///
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import viteTsConfigPaths from 'vite-tsconfig-paths';
@@ -53,6 +55,7 @@ export const someBuildOptions = `
`;
export const noContentDefineConfig = `
+ ///
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import viteTsConfigPaths from 'vite-tsconfig-paths';
@@ -61,6 +64,7 @@ export const noContentDefineConfig = `
`;
export const conditionalConfig = `
+ ///
import { defineConfig } from 'vite';
export default defineConfig(({ command, mode, ssrBuild }) => {
if (command === 'serve') {
@@ -78,6 +82,7 @@ export const conditionalConfig = `
`;
export const configNoDefineConfig = `
+ ///
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import viteTsConfigPaths from 'vite-tsconfig-paths';
@@ -93,6 +98,7 @@ export const configNoDefineConfig = `
`;
export const noBuildOptionsHasTestOption = `
+ ///
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import viteTsConfigPaths from 'vite-tsconfig-paths';
@@ -118,6 +124,7 @@ export const noBuildOptionsHasTestOption = `
`;
export const someBuildOptionsSomeTestOption = `
+ ///
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import viteTsConfigPaths from 'vite-tsconfig-paths';
@@ -142,6 +149,7 @@ export const someBuildOptionsSomeTestOption = `
`;
export const hasEverything = `
+ ///
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import viteTsConfigPaths from 'vite-tsconfig-paths';
diff --git a/packages/vite/src/utils/test-utils.ts b/packages/vite/src/utils/test-utils.ts
index 9752bdd1bb078..e1dfc88278c66 100644
--- a/packages/vite/src/utils/test-utils.ts
+++ b/packages/vite/src/utils/test-utils.ts
@@ -90,7 +90,8 @@ export function mockViteReactAppGenerator(tree: Tree): Tree {
tree.write(
`apps/${appName}/vite.config.ts`,
- `import { defineConfig } from 'vite';
+ ` ///
+ import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import tsconfigPaths from 'vite-tsconfig-paths';
@@ -533,7 +534,8 @@ export function mockReactLibNonBuildableVitestRunnerGenerator(
tree.write(
`libs/${libName}/vite.config.ts`,
- `import { defineConfig } from 'vite';
+ `///
+ import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import viteTsConfigPaths from 'vite-tsconfig-paths';