diff --git a/packages/vite/src/plugins/__snapshots__/plugin-with-test.spec.ts.snap b/packages/vite/src/plugins/__snapshots__/plugin-with-test.spec.ts.snap index f478fab16c9c7e..109416a685f0be 100644 --- a/packages/vite/src/plugins/__snapshots__/plugin-with-test.spec.ts.snap +++ b/packages/vite/src/plugins/__snapshots__/plugin-with-test.spec.ts.snap @@ -46,25 +46,6 @@ exports[`@nx/vite/plugin with test node root project should create nodes - with "buildTarget": "build", }, }, - "test": { - "cache": true, - "command": "vitest run", - "inputs": [ - "default", - "^production", - { - "externalDependencies": [ - "vitest", - ], - }, - ], - "options": { - "cwd": ".", - }, - "outputs": [ - "{projectRoot}/coverage", - ], - }, }, }, }, diff --git a/packages/vite/src/plugins/plugin-vitest.spec.ts b/packages/vite/src/plugins/plugin-vitest.spec.ts index 7af6417c4c912c..c7ae33ceb8aca9 100644 --- a/packages/vite/src/plugins/plugin-vitest.spec.ts +++ b/packages/vite/src/plugins/plugin-vitest.spec.ts @@ -2,7 +2,7 @@ import { CreateNodesContext } from '@nx/devkit'; import { createNodes } from './plugin'; jest.mock('vite', () => ({ - loadConfigFromFile: jest.fn().mockImplementation(() => { + resolveConfig: jest.fn().mockImplementation(() => { return Promise.resolve({ path: 'vitest.config.ts', config: {}, @@ -13,7 +13,7 @@ jest.mock('vite', () => ({ jest.mock('../utils/executor-utils', () => ({ loadViteDynamicImport: jest.fn().mockResolvedValue({ - loadConfigFromFile: jest.fn().mockResolvedValue({ + resolveConfig: jest.fn().mockResolvedValue({ path: 'vitest.config.ts', config: {}, dependencies: [], diff --git a/packages/vite/src/plugins/plugin-with-test.spec.ts b/packages/vite/src/plugins/plugin-with-test.spec.ts index 934a126748825b..a5bcf1aa24ed27 100644 --- a/packages/vite/src/plugins/plugin-with-test.spec.ts +++ b/packages/vite/src/plugins/plugin-with-test.spec.ts @@ -2,7 +2,7 @@ import { CreateNodesContext } from '@nx/devkit'; import { createNodes } from './plugin'; jest.mock('vite', () => ({ - loadConfigFromFile: jest.fn().mockImplementation(() => { + resolveConfig: jest.fn().mockImplementation(() => { return Promise.resolve({ path: 'vite.config.ts', config: { @@ -17,7 +17,7 @@ jest.mock('vite', () => ({ jest.mock('../utils/executor-utils', () => ({ loadViteDynamicImport: jest.fn().mockResolvedValue({ - loadConfigFromFile: jest.fn().mockResolvedValue({ + resolveConfig: jest.fn().mockResolvedValue({ path: 'vite.config.ts', config: { test: { diff --git a/packages/vite/src/plugins/plugin.spec.ts b/packages/vite/src/plugins/plugin.spec.ts index 7e83d56bbf51b1..0d6de07369ac4c 100644 --- a/packages/vite/src/plugins/plugin.spec.ts +++ b/packages/vite/src/plugins/plugin.spec.ts @@ -14,7 +14,7 @@ jest.mock('vite', () => ({ jest.mock('../utils/executor-utils', () => ({ loadViteDynamicImport: jest.fn().mockResolvedValue({ - loadConfigFromFile: jest.fn().mockResolvedValue({ + resolveConfig: jest.fn().mockResolvedValue({ path: 'vite.config.ts', config: {}, dependencies: [], diff --git a/packages/vite/src/plugins/plugin.ts b/packages/vite/src/plugins/plugin.ts index 8e0938e7c24187..70248028db63d4 100644 --- a/packages/vite/src/plugins/plugin.ts +++ b/packages/vite/src/plugins/plugin.ts @@ -92,17 +92,23 @@ async function buildViteTargets( options: VitePluginOptions, context: CreateNodesContext ) { - const { loadConfigFromFile } = await loadViteDynamicImport(); - const viteConfig = await loadConfigFromFile( + const remappedProjectRoot = projectRoot === '.' ? '' : projectRoot; + const absoluteConfigFilePath = joinPathFragments( + context.workspaceRoot, + remappedProjectRoot, + configFilePath + ); + const { resolveConfig } = await loadViteDynamicImport(); + const viteConfig = await resolveConfig( { - command: 'build', + configFile: absoluteConfigFilePath, mode: 'production', }, - configFilePath + 'build' ); const { buildOutputs, testOutputs, hasTest } = getOutputs( - viteConfig?.config, + viteConfig, projectRoot );