harlan-zw / unlighthouse

Scan your entire site with Google Lighthouse in 2 minutes (on average). Open source, fully configurable with minimal setup.
https://unlighthouse.dev
MIT License
3.65k stars 105 forks source link

Relative urls when generating static report #192

Closed BirknerAlex closed 4 months ago

BirknerAlex commented 4 months ago

Describe the bug

I am using --build-static to generate the HTML report in our pipeline. Since I will use Gitlab Pages for the reports and having only one page domain for all branches I move the reports to a relative path.

As example when having the Pages URL https://project.pages.domain.com, will move the reports to https://project.pages.domain.com/<branch>/. This does not work since all asset urls are using absolute paths in the generated index.html, css and js files.

I am currently replacing them with sed -i 's/\/assets\//assets\//g' public/$UNLIGHTHOUSE_REPORT_PATH/index.html. This works for the most but some assets are still requested from the absolute URL which results in an 404 response from the webserver.

Example:

# URL in rendered HTML
https://project.pages.domain.com/reports/en/news/screenshot.jpeg

# Real URL:
https://project.pages.domain.com/<branch>reports/en/news/screenshot.jpeg

Reproduction

No response

System / Nuxt Info

No response

thibaudcolas commented 4 months ago

👋 you’re looking for the routerPrefix / --router-prefix option I believe. See #11.

harlan-zw commented 4 months ago

Thanks, @thibaudcolas, this is the right solution so I'll close this.