From 27169820a2547b5234d8b4cad3034ed28e2507ca Mon Sep 17 00:00:00 2001 From: userquin Date: Wed, 6 Nov 2024 13:06:21 +0100 Subject: [PATCH] feat(nuxt): update imports module with unimport addon changes --- packages/nuxt/src/imports/module.ts | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/nuxt/src/imports/module.ts b/packages/nuxt/src/imports/module.ts index 33aad9a885..ea1894afd5 100644 --- a/packages/nuxt/src/imports/module.ts +++ b/packages/nuxt/src/imports/module.ts @@ -1,7 +1,7 @@ import { existsSync } from 'node:fs' import { addBuildPlugin, addTemplate, addTypeTemplate, defineNuxtModule, isIgnored, logger, resolveAlias, tryResolveModule, updateTemplates, useNuxt } from '@nuxt/kit' import { isAbsolute, join, normalize, relative, resolve } from 'pathe' -import type { Import, Unimport } from 'unimport' +import type { AddonsOptions, Import, Unimport } from 'unimport' import { createUnimport, scanDirExports, toExports } from 'unimport' import type { ImportPresetWithDeprecation, ImportsOptions, ResolvedNuxtTemplate } from 'nuxt/schema' import escapeRE from 'escape-string-regexp' @@ -41,14 +41,23 @@ export default defineNuxtModule>({ // Filter disabled sources // options.sources = options.sources.filter(source => source.disabled !== true) + const { addons: inlineAddons, ...rest } = options + + const addons: AddonsOptions = { + addons: inlineAddons && Array.isArray(inlineAddons) + ? [...inlineAddons] + : [], + vueDirectives: inlineAddons && !Array.isArray(inlineAddons) + ? inlineAddons.vueDirectives + : options.autoImport === false ? undefined : true, + vueTemplate: options.autoImport, + } + // Create a context to share state between module internals const ctx = createUnimport({ injectAtEnd: true, - ...options, - addons: { - vueTemplate: options.autoImport, - ...options.addons, - }, + ...rest, + addons, presets, })