Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add unimport plugin for Nitro support #757

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { DotenvOptions } from 'c12'
import type { InlineConfig } from 'vite'
import { defu } from 'defu'
import { createResolver } from '@nuxt/kit'
import Unimport from 'unimport/unplugin'

import { applyEnv } from './utils'

Expand Down Expand Up @@ -89,6 +90,17 @@ export async function getVitestConfigFromNuxt(
}

options.viteConfig.plugins = (options.viteConfig.plugins || []).filter(p => !excludedPlugins.includes((p as any)?.name))

const nitro = (options.nuxt as any)?._nitro

if (nitro) {
// Nitro Plugin
options.viteConfig.plugins.push(Unimport.vite({
imports: [
...nitro.unimport.getImports(),
]
}))
}

const resolvedConfig = defu(
// overrides
Expand Down Expand Up @@ -174,6 +186,12 @@ export async function getVitestConfigFromNuxt(
}
}
} satisfies VitestConfig
},
// (overrideable) alias
{
alias: {
...nitro ? nitro.options.alias : {}
}
}
) as InlineConfig & { test: VitestConfig }

Expand Down
Loading