plasmicapp / plasmic

Visual builder for React. Build apps, websites, and content. Integrate with your codebase.
https://www.plasmic.app
MIT License
4.78k stars 384 forks source link

Honoring Base Href in plasmic build #22

Closed mcgear closed 7 months ago

mcgear commented 2 years ago

Is it possible to get plasmic to generate relative paths that honor the base href setting? currently i can't host plasmic rooted on say the /home path of our site.

mcgear commented 2 years ago

I did find that i was able to get the JS and CSS from next.js to compile using basePath: /home.... However non of the images are honoring.

Honoring base href would be the most ideal solution

gabrielpessoa1 commented 2 years ago

Hello, we found a bug on our "Button" interactive component where it is not honoring the base href setting, do you also have this problem when using directly a Link/ element on studio? either way we are looking into it to provide a fix.

mcgear commented 2 years ago

Yes with the button, though how it honors base href should be dependent on how a link is setup. We still need to be able to use a link like '/docs' to go to a root site location and a link to 'docs' to honor base href.

My specific issue has more to do with the generated index.html file and how it references the js/css files. When i looked at it more, it seemed a bit of an issue with next.js itself.

When we set the basePath to '/home' so that we could host it on a '/home' path on our site, that worked for the JS/CSS, but did not work for images (images were still trying to pull from root /plasmic instead of /home/plasmic).

I think, in an ideal world, image paths would not be /plasmic but rather just 'plasmic' and js/css would be '_next' instead of '/_next'. Then, with the use of <base href="/home/"> i could achieve the local context of plasmic, allowing me to host a plasmic site on any path on my domain, instead of theoretically using plasmic for everything (bit of a micro-frontends approach we have going on).

mcgear commented 2 years ago

After writing that, maybe the image issue and the button issue are similar? And if those were fixed and honored base href, then at least the basePath option in next.config would be back on the table.

gabrielpessoa1 commented 2 years ago

Thanks for the detailed report, we will work on this.

plasmicops commented 2 years ago

Hi @mcgear, are you using codegen with next.js? If you look at your plasmic.json, do you see that it's using images.scheme: "public-files"? If so, you can try updating your plasmic.json file to set something like...

"images": {
  "scheme": "public-files",
  "publicDir": "../public",
  "publicUrlPrefix": "/home"
}

The publicUrlPrefix will be prepended to the image src url, which should point to the right place?