Skip to content

Commit

Permalink
feat: allow ignoring directives (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
userquin authored Jul 12, 2024
1 parent 210eeec commit 833132e
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 5 deletions.
7 changes: 4 additions & 3 deletions docs/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Theme from 'vitepress/theme'
import type { Theme } from 'vitepress'
import DefaultTheme from 'vitepress/theme'
import { inBrowser } from 'vitepress'
import VuetifyLayout from './VuetifyLayout.vue'

Expand All @@ -11,6 +12,6 @@ if (inBrowser)
import('./pwa')

export default {
...Theme,
extends: DefaultTheme,
Layout: VuetifyLayout,
}
} satisfies Theme
4 changes: 4 additions & 0 deletions docs/guide/globals/directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ By default, the module will not register any Vuetify directive. If you need to r

You can register all the directives or only the ones you need: check the [directives definition](https://github.com/userquin/vuetify-nuxt-module/blob/main/src/types.ts#L91-L92).

## Ignore directives <Badge type="tip" text="from v0.15.1" />

If you want to ignore some directives, you can use the `moduleOptions.ignoreDirectives` option. The module will configure the Vuetify Vite Plugin to [ignore](https://github.com/vuetifyjs/vuetify-loader/tree/master/packages/vite-plugin#ignoring-components-or-directives) the directives you specify.

## Examples

### Registering all the directives
Expand Down
6 changes: 6 additions & 0 deletions docs/guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ export interface MOptions {
* @default true
*/
includeTransformAssetsUrls?: boolean | Record<string, string[]>
/**
* Directives Vuetify Vite Plugin should ignore.
*
* @since v0.15.1
*/
ignoreDirectives?: DirectiveName | DirectiveName[]
/**
* Vuetify SSR client hints.
*
Expand Down
6 changes: 6 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,12 @@ export interface MOptions {
* @default true
*/
includeTransformAssetsUrls?: boolean | Record<string, string[]>
/**
* Directives Vuetify Vite Plugin should ignore.
*
* @since v0.15.1
*/
ignoreDirectives?: DirectiveName | DirectiveName[]
/**
* Vuetify SSR client hints.
*
Expand Down
13 changes: 12 additions & 1 deletion src/utils/configure-vite.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Nuxt } from '@nuxt/schema'
import defu from 'defu'
import type { Options } from '@vuetify/loader-shared'
import { vuetifyStylesPlugin } from '../vite/vuetify-styles-plugin'
import { vuetifyConfigurationPlugin } from '../vite/vuetify-configuration-plugin'
import { vuetifyIconsPlugin } from '../vite/vuetify-icons-configuration-plugin'
Expand Down Expand Up @@ -41,7 +42,17 @@ export function configureVite(configKey: string, nuxt: Nuxt, ctx: VuetifyNuxtCon
viteInlineConfig.vue.template.transformAssetUrls = transformAssetUrls
}

viteInlineConfig.plugins.push(vuetifyImportPlugin({}))
// fix #236
const vuetifyImportOptions: Options = {}
const ignoreDirectives = ctx.moduleOptions.ignoreDirectives
if (ignoreDirectives) {
const ignore = Array.isArray(ignoreDirectives)
? ignoreDirectives
: [ignoreDirectives]
vuetifyImportOptions.autoImport = { ignore }
}

viteInlineConfig.plugins.push(vuetifyImportPlugin(vuetifyImportOptions))
viteInlineConfig.plugins.push(vuetifyStylesPlugin({ styles: ctx.moduleOptions.styles }, ctx.logger))
viteInlineConfig.plugins.push(vuetifyConfigurationPlugin(ctx))
viteInlineConfig.plugins.push(vuetifyIconsPlugin(ctx))
Expand Down
3 changes: 2 additions & 1 deletion src/vite/vuetify-import-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { extname } from 'node:path'
import { pathToFileURL } from 'node:url'
import type { Plugin } from 'vite'
import { type Options, generateImports } from '@vuetify/loader-shared'
import type { Options } from '@vuetify/loader-shared'
import { generateImports } from '@vuetify/loader-shared'
import { parseQuery, parseURL } from 'ufo'
import { isAbsolute } from 'pathe'
import destr from 'destr'
Expand Down

0 comments on commit 833132e

Please sign in to comment.