-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnuxt.ts
54 lines (47 loc) · 1.74 KB
/
nuxt.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Workaround for:
// src/nuxt.ts(5,1): error TS2742: The inferred type of 'default' cannot be named without a reference to '.pnpm/@[email protected][email protected]/node_modules/@nuxt/schema'. This is likely not portable. A type annotation is necessary.
import type { } from '@nuxt/schema'
import type { ExternalPluginOptionsFolder, ExternalPluginOptionsFunction } from './types'
import type { SFCPluginOptions } from './vite'
import { addVitePlugin, defineNuxtModule } from '@nuxt/kit'
import { directiveTransform } from './directive-transform'
import { ExternalFluentPlugin, SFCFluentPlugin } from './vite'
interface NuxtFluentOptions {
sfc?: SFCPluginOptions
external?: Omit<ExternalPluginOptionsFolder, 'baseDir'> | ExternalPluginOptionsFunction
/**
* @default 't' v-t directive name for the directive transform
*/
directiveName?: string
}
export default defineNuxtModule<NuxtFluentOptions>({
meta: {
name: 'fluent-vue',
configKey: 'fluentVue',
},
setup(options, nuxt) {
if (!options.sfc && !options.external) {
console.error(`[fluent-vue/nuxt] You need to enable at least one of the fluent-vue plugins`)
return
}
nuxt.options.vue.compilerOptions.directiveTransforms ??= {}
nuxt.options.vue.compilerOptions.directiveTransforms[options.directiveName ?? 't'] = directiveTransform
if (options.sfc)
addVitePlugin(SFCFluentPlugin(options.sfc))
if (options.external) {
const externalOptions = {
...options.external,
baseDir: nuxt.options.srcDir,
}
addVitePlugin(ExternalFluentPlugin(externalOptions))
}
},
})
declare module '@nuxt/schema' {
interface NuxtConfig {
fluentVue?: NuxtFluentOptions
}
interface NuxtOptions {
fluentVue?: NuxtFluentOptions
}
}