nuxt-alias-path

Cross-platform builds a path for nuxt.options.alias in modules. Passing a path straight away causes issues on Windows.

OTHER License

Downloads
5K
Stars
0
Committers
4

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:

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! ❤️

License

MIT License © Sebastian Landwehr