How to get project directory in nuxt kit ?
I want to create a nuxt module with nuxt kit that add a custom alias.
But to do this I need to have the project dir :
How can I acheve such a thing ?
8 Replies
use the createResolver function
you should be able to import like that, if not you have access to
nuxt.options.rootDir
This seems to work pretty well with
resolvePath('mylib')
.
However I am using sass
and it cannot find import : @import '~mylib/mystyle.scss'
I am doing thing right, or for sass i need something else ?hm ye this requires something else maybe, let me think
does it show the alias resolving at all?
In the tsconfig.json file generated by nuxt it seems good. But sass doesn't seem to resolve at all
hm it says they should be respected
Vite aliases are also respected for CSS @importis this in dev and built?
If I try to import the scss file in a ts file, it doesn't resolve import as well. I think there is something wrong with my configuration.
that doesn't seem like something nuxt would support
what are you trying to do exactly
Okay I think I found the issue.
I am trying to create a nuxt module 'mylib-nuxt'. I want 'mylib-nuxt' to expose 'mylib-styles' as an alias to 'mylib/styles/*.scss'.
The issue comes from the
resolvePath('mylib/styles')
which resolve to mylib/dist/node_modules/mylib
. I want the dist
part away. Maybe I should just use resolvePath('../mylib/styles')
?
Okay this was the solution :
On the nuxt module :
nuxt.options.alias['mylib-styles'] = await resolvePath('~~/node_modules/mylib/styles)
And in the scss file : @import "mylib-styles/mixins.scss";