-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathmodule.ts
46 lines (37 loc) · 1.15 KB
/
module.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
import { defineNuxtModule, addPlugin, createResolver } from '@nuxt/kit'
// https://github.com/nuxt/module-builder/issues/242
import type { SharedTypeFromRuntime } from './runtime/plugins/plugin'
// Module options TypeScript interface definition
export interface ModuleOptions {
apiKey: string
shared?: SharedTypeFromRuntime
}
export interface ModuleHooks {
'my-module:init': (sharedType: SharedTypeFromRuntime) => void
}
export interface ModuleRuntimeHooks {
'my-module:runtime-hook': () => void
}
export interface ModulePublicRuntimeConfig {
NAME: string
}
export interface ModuleRuntimeConfig {
PRIVATE_NAME: string
}
export default defineNuxtModule<ModuleOptions>({
meta: {
name: 'my-module',
configKey: 'myModule',
},
// Default configuration options of the Nuxt module
defaults: {
apiKey: '',
},
setup(_options, _nuxt) {
const resolver = createResolver(import.meta.url)
// @ts-expect-error type should be resolved
_options.shared = 'not-shared-type'
// Do not add the extension since the `.ts` will be transpiled to `.mjs` after `npm run prepack`
addPlugin(resolver.resolve('./runtime/plugins/plugin'))
},
})