nuxt-alias-path
v2.0.0
Published
Cross-platform builds a path for nuxt.options.alias in modules. Passing a path straight away causes issues on Windows.
Downloads
4,710
Readme
nuxt-alias-path
Cross-platform builds a path for nuxt.options.alias in modules. Passing a path straight away causes issues on Windows.
When you just write nuxt.options.alias['#foo'] = path
in your Nuxt module, the dev server will not work on Windows. This module is a helper that fixes the issue and will hopefully eventually be fixed in Nuxt.
See here some modules also having the issue:
- https://github.com/dword-design/nuxt-mail/issues/143
- https://github.com/nuxt-modules/robots/issues/86
- https://github.com/nuxt/nuxt/issues/15500
Install
# npm
$ npm install nuxt-alias-path
# Yarn
$ yarn add nuxt-alias-path
Usage
import nuxtAliasPath from 'nuxt-alias-path'
import { addTemplate } from '@nuxt/kit'
export default defineNuxtModule((options, nuxt) => {
addTemplate({
filename: 'mod.mjs',
getContents: () => "export default { foo: 'bar' }",
write: true,
})
nuxt.options.alias['#mod'] = nuxtAliasPath('mod.mjs', JSON.stringify(options))
})
Then use the alias somewhere else:
import foo from '#mod'
Contribute
Are you missing something or want to contribute? Feel free to file an issue or a pull request! ⚙️
Support
Hey, I am Sebastian Landwehr, a freelance web developer, and I love developing web apps and open source packages. If you want to support me so that I can keep packages up to date and build more helpful tools, you can donate here:
Thanks a lot for your support! ❤️