larsmyrup
larsmyrup
NNuxt
Created by brick on 9/17/2024 in #❓・help
Adding Types To Nuxt Module
@zoobzio Thanks for getting back! We're using the nuxt-module-builder and trying to follow the pattern established by component libraries like Nuxt UI. Which seems to do the same. However i agree that having d.ts-files in the runtime folder seems off and like i'm missing something 😅
14 replies
NNuxt
Created by brick on 9/17/2024 in #❓・help
Adding Types To Nuxt Module
This code:
const types = [
'ValidationMode',
'FieldWithValidationProps',
]

types.forEach((type) => {
addImports({
name: type,
from: resolver.resolve('runtime/types'),
type: true,
})
})
const types = [
'ValidationMode',
'FieldWithValidationProps',
]

types.forEach((type) => {
addImports({
name: type,
from: resolver.resolve('runtime/types'),
type: true,
})
})
Made my types be globally available in the consuming application, so that's great. But i'm still very open to hear any ideas for making it happen more "automatically", importing the entire directory or similar.
14 replies
NNuxt
Created by brick on 9/17/2024 in #❓・help
Adding Types To Nuxt Module
Hey @Sybrn Thanks for contributing! Personally i can't see why that code wouldn't work.. hm. Seems like we're in the same boat.. Let me know if you manage to crack it - and i'll make sure to do the same!
14 replies
NNuxt
Created by brick on 9/17/2024 in #❓・help
Adding Types To Nuxt Module
Hi @zoobzio, Thanks for the answer! It's very appreciated. I've been trying using addImportsDir - and while it works for composables, utils etc. i can't get it to work for types. I have a types-folder and add it like: addImportsDir(resolver.resolve('runtime/types')) And everything seems to work in the playground. But if i publish the package with yalc (should be similar to npm, but makes testing locally a bit easier) and install it in another application i get this warning: WARN [unimport] failed to resolve "{path}/dist/runtime/types/field-with-validation", skip scanning Even though i can see the field-with-validation.d.ts field in the node_modules folder of the package. Do you have any ideas? Also when i run the playground in dev mode, types gets added to the .nuxt/imports.d.ts-file, but when i install the module in another project, that's not the case. Even though the utils, composables etc. all are in there. I'll try the addImportsSources, but it seems like it's more used for adding other dependencies types, than the ones i've defined myself in the module.
14 replies
NNuxt
Created by brick on 9/17/2024 in #❓・help
Adding Types To Nuxt Module
Hey Brick I'm having some similar challenges. Did you manage to solve this?
14 replies