1- import { defineNuxtModule , addImports , addComponent } from '@nuxt/kit'
1+ import {
2+ defineNuxtModule ,
3+ addImports ,
4+ addComponent ,
5+ createResolver ,
6+ } from '@nuxt/kit'
27
38import { name , version } from '../package.json'
49
@@ -20,26 +25,26 @@ export default defineNuxtModule<ModuleOptions>({
2025 lowlight : false ,
2126 } ,
2227 async setup ( options , nuxt ) {
28+ const resolver = createResolver ( import . meta. url )
29+
2330 const transpileModules = new Set < string > ( [ ] )
2431
2532 const defaultComposables : ImportObject [ ] = [
2633 ...allImports . defaultComposables ,
27- ...allImports . customComposables ,
2834 ]
2935
30- const defaultImports : ImportObject [ ] = [
31- ...allImports . defaultImports ,
32- ...allImports . customImports ,
33- ]
36+ const defaultImports : ImportObject [ ] = [ ...allImports . defaultImports ]
3437
35- const defaultComponents : ImportObject [ ] = [
36- ...allImports . defaultComponents ,
37- ...allImports . customComponents ,
38- ]
38+ const defaultComponents : ImportObject [ ] = [ ...allImports . defaultComponents ]
3939
4040 const optionalImports : ImportObject [ ] = [ ]
4141 const optionalComposables : ImportObject [ ] = [ ]
4242 const optionalComponents : ImportObject [ ] = [ ]
43+
44+ const customComposables : ImportObject [ ] = [ ...allImports . customComposables ]
45+ const customImports : ImportObject [ ] = [ ...allImports . customImports ]
46+ const customComponents : ImportObject [ ] = [ ...allImports . customComponents ]
47+
4348 const customCSS : string [ ] = [ ]
4449
4550 for ( const obj of defaultComposables ) {
@@ -76,7 +81,7 @@ export default defineNuxtModule<ModuleOptions>({
7681
7782 const lldefaultTheme = options . lowlight ?. theme || 'github-dark'
7883 const highlightJSVersion
79- = options . lowlight ?. highlightJSVersion || '11.10.0'
84+ = options . lowlight ?. highlightJSVersion || '11.10.0'
8085 const llThemeCSS = `https://unpkg.com/@highlightjs/cdn-assets@${ highlightJSVersion } /styles/${ lldefaultTheme } .min.css`
8186
8287 nuxt . options . app . head . link = [
@@ -112,6 +117,30 @@ export default defineNuxtModule<ModuleOptions>({
112117 transpileModules . add ( obj . path )
113118 }
114119
120+ for ( const obj of customImports ) {
121+ addImports ( {
122+ as : `${ options . prefix } ${ obj . name } ` ,
123+ name : obj . name ,
124+ from : resolver . resolve ( obj . path ) ,
125+ } )
126+ }
127+
128+ for ( const obj of customComposables ) {
129+ addImports ( {
130+ as : obj . as || obj . name ,
131+ name : obj . name ,
132+ from : resolver . resolve ( obj . path ) ,
133+ } )
134+ }
135+
136+ for ( const obj of customComponents ) {
137+ addComponent ( {
138+ name : `${ options . prefix } ${ obj . name } ` ,
139+ export : obj . name ,
140+ filePath : resolver . resolve ( obj . path ) ,
141+ } )
142+ }
143+
115144 nuxt . options . build . transpile = [
116145 ...nuxt . options . build . transpile ,
117146 ...Array . from ( transpileModules ) ,
0 commit comments