Skip to content

Commit 6059d29

Browse files
committed
fix: custom imports
1 parent 9fbeffe commit 6059d29

File tree

8 files changed

+42
-14
lines changed

8 files changed

+42
-14
lines changed

src/imports/custom.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import path from 'node:path'
21
import type { ImportObject } from '../types'
32

4-
const customExtensionPath = '../custom-extensions'
3+
const customExtensionPath = 'runtime/custom-extensions'
54
const resolveCustomExtension = (extPath: string) =>
6-
path.resolve(__dirname, customExtensionPath, extPath)
5+
`${customExtensionPath}/${extPath}`
76

87
export const defaultCustomExtensions: ImportObject[] = [
98
{

src/module.ts

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { defineNuxtModule, addImports, addComponent } from '@nuxt/kit'
1+
import {
2+
defineNuxtModule,
3+
addImports,
4+
addComponent,
5+
createResolver,
6+
} from '@nuxt/kit'
27

38
import { 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),

src/custom-extensions/extension-image-upload/ImagePlaceholder.vue renamed to src/runtime/custom-extensions/extension-image-upload/ImagePlaceholder.vue

File renamed without changes.

src/custom-extensions/extension-image-upload/imagePlaceholder.ts renamed to src/runtime/custom-extensions/extension-image-upload/imagePlaceholder.ts

File renamed without changes.

src/custom-extensions/extension-image-upload/imageUpload.ts renamed to src/runtime/custom-extensions/extension-image-upload/imageUpload.ts

File renamed without changes.

src/custom-extensions/extension-image-upload/imageUploader.ts renamed to src/runtime/custom-extensions/extension-image-upload/imageUploader.ts

File renamed without changes.

src/custom-extensions/extension-image-upload/index.ts renamed to src/runtime/custom-extensions/extension-image-upload/index.ts

File renamed without changes.

0 commit comments

Comments
 (0)