Skip to content

Need a way to use static resources with router.base #4544

@loilo

Description

@loilo

What problem does this feature solve?

Currently, there's no (documented) way to properly use static assets in sites deployed by Nuxt's generate command when the router.base coption is set to something other than /. Resources requested as ~/path/to/resource are correctly rewritten to [router.base]/path/to/resource. Unfortunately, there's no equivalent to that for static resources requested as /resource.


The real-world situation is simple:

  • We develop a site locally under http://localhost:3000/.
  • We want to deploy it as a static site to https://our-site.com/demo, so in production it gets the router.base option set to /demo.

Therefore in local development all static resources should point to / whereas in production they should point to /demo/.

I have created a minimal repro that explains this by example, much better than I could do here in words.

To kickstart the repro, just run:

npx github:Loilo/repro-nuxt-static-base

I believe this is the same issue that has been brought up in #2753.
It has been addressed with the introduction of the render.static.prefix option in #2755 which is however completely undocumented and it's unclear to me how it may solve the issue.

What does the proposed changes look like?

If the render.static.prefix option is actually able to solve this (which I think it's meant to be), it should be documented.

Otherwise, an additional render.static.* option could be introduced to control rewriting requests to static resources.

This feature request is available on Nuxt community (#c8302)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions