Cross-platform builds a path for nuxt.options.alias in modules. Passing a path straight away causes issues on Windows.
OTHER License
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:
# npm
$ npm install nuxt-alias-path
# Yarn
$ yarn add nuxt-alias-path
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'
Are you missing something or want to contribute? Feel free to file an issue or a pull request! ⚙️
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! ❤️