最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to I configure a relative path to use when generating build outputs in Vite? - Stack Overflow

programmeradmin6浏览0评论

In my app, when I do npm run dev I can test fine on http://localhost:3000. But for the output build, where I run it, is part of another application sub folder. For example, the links ends up being like as I dump the dist output from the vite app into the reconstatus folder and to view the app I just go to .html. I noticed a problem where the generated code links to the js/css/etc... set by vite start with a slash, so relative to the root, but this results in 404 can't find files, since now the files are in /docs/reconstatus. Is there a way to tell vite, for build outputs, set the links to use a certain path like /docs/reconstatus?

In my app, when I do npm run dev I can test fine on http://localhost:3000. But for the output build, where I run it, is part of another application sub folder. For example, the links ends up being like http://myapp./docs/reconstatus as I dump the dist output from the vite app into the reconstatus folder and to view the app I just go to http://myapp./docs/reconstatus/index.html. I noticed a problem where the generated code links to the js/css/etc... set by vite start with a slash, so relative to the root, but this results in 404 can't find files, since now the files are in /docs/reconstatus. Is there a way to tell vite, for build outputs, set the links to use a certain path like /docs/reconstatus?

Share Improve this question asked Jun 9, 2023 at 18:36 omegaomega 44k90 gold badges286 silver badges523 bronze badges 1
  • vitejs.dev/config/server-options.html#server-base maybe? – Arleigh Hix Commented Jun 9, 2023 at 19:11
Add a ment  | 

1 Answer 1

Reset to default 6

I assume you want to configure your public base path for your vite build. Tell me if i am wrong and i will edit the answer.

To configure the public build path pass it as a argument during the build process.

vite build --base=/my/public/path/

source: vite docs

发布评论

评论列表(0)

  1. 暂无评论