Skip to content

SSG export: support for base paths #5550

@baer95

Description

@baer95

I've been trying to export my site and and deploy an ssg build to a subpath, but it seems that currently only root deployments are supported (this limitation is not mentioned in the docs).

After spending some time to figure out how the ssg template generation works, I managed to patch my build process to make all paths work correctly when deploying to a subpath.

I would like to submit a PR to webstudio to improve the ssg template and bring this feature to everyone, and I am here to check in with the maintainers and agree on a solution (I wanted to reach out on discord but the invite link in the docs is invalid).

Thanks a lot!

What I did so far

Note that I mostly work with infrastructure, pipelines and automations, and UI components are not my strongest case :).

CSS and JS assets are covered by setting the base option in vite.

Navigation links in app/__generated__/* files use the Link component which currently does not support prefixing with a base path during build time.

  • I wrote a very basic vite pre-build hook that prefixes values of href attributes.
  • I am not sure how to implement this correctly because the Link component is marked as @deprecated.

Image URLs are run through the imageLoader during the build, but it passes the given file path through without modifications.

  • I fixed this by prefixing the given src with import.meta.env.BASE_URL.

Other assets like the social image, favicon, fonts and background images inside the +Head.tsx component are both passed through the imageLoader without modifications and prefixed with the assetBaseUrl.

  • I fixed this by introducing a new assetLoader next to the imageLoader which prefixes the given path with both the base path and the assetBaseUrl. With this, the component does not need to import assetBaseUrl anymore.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions